开发者

iPhone - showing a message on a UITableViewController

I have a class that shows messages on views for a few seconds then vanishes. When I would like to show a message o开发者_运维问答n a viewController I simply create the message object based on that class and fire that object. Something like:

myMessageClass *message = [[myMessageClass alloc] init];
[self.view addSubview:message];
[message release];
[message showText:@"Hello world"];

but now I am using this message class on a UITableViewController class. How do I show the message on top of the table, without being tied to the table itself.

I have tried to add the view like this:

[self.tableView addSubview:message];

but the message will move if the table moves. I just have to have the message in a fixed position (no, the table header or footer has no enough height to show the message object]. No, I don't want to use an alertView.

Is there an Apple blessed way to do that?


Check out http://code.google.com/p/toast-notifications-ios/ . This sounds like the equivalent of an Android Toast.

Of course you know that you could make your life a bit easier by using a regular UIViewController subclass with a UITableView and set it as a data source/delegate. Short of this, in a UITableViewController class, UITableView = View so you are going to have a rough time. The only way I can think of is to respond to scrolling movements in the view using the delegate methods, ie -(void)scrollViewDidEndDecelerating.

For example:

-(void)scrollViewDidEndDecelerating: (UIScrollView *)scrollView {
    CGFloat offset = scrollView.contentOffset.y;
    self.message.frame = CGRectMake(self.message.frame.origin.x,self.message.frame.origin.y + offset,self.message.frame.size.width,self.message.frame.size.height);
}

This may not be exactly right but along the lines of what you need probably.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜