【发布时间】:2014-05-06 11:21:06
【问题描述】:
我尝试调用委托方法,但没有。我应该在我的代码中更改什么?谢谢。
我尝试在 Class1.m 中添加:
+(void)popupAlert:(NSString*)msg tag:(NSInteger)tag{
Class1 *c= [[Class1 alloc]init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:msg
delegate:c (I also tried c.self)
cancelButtonTitle:...
otherButtonTitles:...,nil];
alert.tag=tag;
[alert show];
}
我尝试设置 alertview 委托来调用这个委托方法。
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
这是我正在做的事情: Class1.h:
+(void)popupAlert:(NSString*)msg tag:(NSInteger)tag;
Class1.m:
+(void)popupAlert:(NSString*)msg tag:(NSInteger)tag{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:msg
delegate:self
cancelButtonTitle:...
otherButtonTitles:...,nil];
alert.tag=tag;
[alert show];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
//some coding
}
Class2.m:
-(void)func1{
[Class1 popupAlert:@"blah blah" tag:0];
}
【问题讨论】:
-
您的代码中有很多问题和严重错误。您应该考虑阅读有关 iOS 开发和 Objective-C 的初学者书籍。
-
将
+方法更改为-方法。 Class2 应该有一个 Class1 对象(作为一个属性),它将为其调用方法。 -
@dasdom 我会的。但你能具体说明问题和错误是什么吗?所以我可以更深入地了解它们。谢谢。
-
1.名称。 Objective-C 非常冗长。 2. 内存管理和范围。当
popupAlert返回时,c 将消失。 3. 类方法和实例方法的区别。 -
感谢您的回答。我会尝试编辑我的代码。
标签: ios objective-c delegates uialertview