Iphone 如何使用UIActionSheet切换视图?

Iphone 如何使用UIActionSheet切换视图?,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,当按下“取消”按钮时,如何使用UIActionSheet切换视图 代码4.3.2 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex]; if ([buttonTitle isEqualToString:@"

当按下“取消”按钮时,如何使用UIActionSheet切换视图

代码4.3.2

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
    if ([buttonTitle isEqualToString:@"Done"]) {
        thiredViewController *controller1 = [[thiredViewController alloc] initWithNibName:@"thiredViewController" bundle:nil];
        [self presentModalViewController:controller1 animated:NO];
    }
}
这段代码什么都不做,视图没有改变,我的朋友告诉我,我不能用这个方法在新的Xcode中改变视图,那么我应该用什么呢?

你永远不应该比较按钮的标题来决定采取哪种操作。如果您决定在其他地方更改它,但同时忘记更改委托方法,该怎么办?如果你用多种语言本地化你的应用程序,这也会变得一团糟

UIActionSheet
有一个方便的
cancelButtonIndex
方法,您可以使用它:

if (buttonIndex == actionSheet.cancelButtonIndex) {
    //do your thing...
}

-(void)actionSheet:(UIActionSheet*)actionSheet ClickedButtonIndex:(NSInteger)buttonIndex{NSString*buttonTitle=[actionSheet ButtonTitleIndex:buttonIndex];if([buttonTitle IseQualtString:@“Done”]){ThirdViewController*controller1=[[ThirdViewController alloc]initWithNibName:@“ThirdViewController”捆绑包:nil];[self-presentModalViewController:controller1动画:否];}}我将您的代码添加到您的问题中,并正确设置了格式。如果你想对你的问题有一个答案,请花点时间让读者感到方便,否则可能没有人会打扰你。非常感谢,但是我用来切换视图的方法是什么,正确与否?因为它不适用于meEdit,所以您的问题需要更详细地说明它是如何工作的以及实际发生了什么。没有发生任何事情,视图没有改变,我的朋友告诉我,我不能在Xcode 4.3.2中使用此代码