开发者

How to prevent TTPostController's modal view from being dismissed upon errors?

For those of you who use three20's TTPostController, how do you go about handling user errors before and after sending a request? i.e., if a user tries to post a blank comment, I want to be able to alert them and keep the view active so they can fix it.

The problem I'm having though is getting the modal view to stay open after things go wrong. I can alert the user, but once they click OK, the modal gets dismissed. I thought I was going be able to use TTPostControllerDelegate:willPostText delegate to accomplish this, but that doesn't seem to be working, or I'm not understanding exactly how it's designed to work.

What i'm doing:

/**
 * The user has posted text and an animation is about to show the text return to its origin.
 *
 * @return whether to dismiss the controller or wait for the user to call dismiss.
 */
- (BOOL)postController:(TTPostController*)postController willPostText:(NSString*)text {
    if ([text length] == 0) {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil 
                                                         message:@"Your message is blank" 
                                                        delegate:self 
                                               cancelButtonTitle:@"OK" 
                                               otherButtonTitles:nil ];
        [alert show];
        [alert release];    

        return false;
    }        
    return true;
}

If I try posting a blank comment, I get an alert letting me know, but once I press OK, the modal view get's dismissed.

Is there something I'm missing or not understanding correctly?

Edit: I should also note that I tried 开发者_Python百科using alertView's didDismissWithButtonIndex: method to try and stop the view from unloading, but i wasn't successful.


I ran into this the other day. If you pass nil instead of self as the delegate into:

UIAlertView initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles 

the TTPostController is no longer dismissed when the user touches "OK".

- (BOOL)postController:(TTPostController*)postController willPostText:(NSString*)text {
    if ([text length] == 0) {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil 
                                                         message:@"Your message is blank" 
                                                        delegate:nil 
                                               cancelButtonTitle:@"OK" 
                                               otherButtonTitles:nil ];
        [alert show];
        [alert release];    

        return false;
    }        
    return true;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜