首先,我刚刚开始 iPhone 开发。我正在尝试使 SBTableAlert 正常工作(请参阅https://github.com/blommegard/SBTableAlert)
我的初始设置很简单:我有一个带有按钮的 UIViewController。在按下按钮时,我执行以下操作(根据 SBTableAlert 示例):
- (IBAction)myBtn_Press
{
SBTableAlert *alert;
alert = [[SBTableAlert alloc] initWithTitle:@"Apple Style" cancelButtonTitle:@"Cancel" messageFormat:nil];
[alert.view setTag:2];
[alert setStyle:SBTableAlertStyleApple];
MySecondViewController *myWGVC = [[MySecondViewController alloc] init];
[alert setDelegate:myWGVC];
[alert setDataSource:myWGVC];
[alert show];
}
MySecondViewController 声明为:
@interface MySecondViewController : NSObject <SBTableAlertDelegate, SBTableAlertDataSource>
这意味着它将充当表视图的委托。我还包括以下内容(从示例中粘贴):
@implementation MySecondViewController
#pragma mark - SBTableAlertDataSource
- (UITableViewCell *)tableAlert:(SBTableAlert *)tableAlert cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (tableAlert.view.tag == 0 || tableAlert.view.tag == 1) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
} else {
// Note: SBTableAlertCell
cell = [[SBTableAlertCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
[cell.textLabel setText:[NSString stringWithFormat:@"Cell %d", indexPath.row]];
return cell;
}
- (NSInteger)tableAlert:(SBTableAlert *)tableAlert numberOfRowsInSection:(NSInteger)section {
if (tableAlert.type == SBTableAlertTypeSingleSelect)
return 3;
else
return 10;
}
- (NSInteger)numberOfSectionsInTableAlert:(SBTableAlert *)tableAlert {
if (tableAlert.view.tag == 3)
return 2;
else
return 1;
}
- (NSString *)tableAlert:(SBTableAlert *)tableAlert titleForHeaderInSection:(NSInteger)section {
if (tableAlert.view.tag == 3)
return [NSString stringWithFormat:@"Section Header %d", section];
else
return nil;
}
#pragma mark - SBTableAlertDelegate
- (void)tableAlert:(SBTableAlert *)tableAlert didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableAlert.type == SBTableAlertTypeMultipleSelct) {
UITableViewCell *cell = [tableAlert.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
else
[cell setAccessoryType:UITableViewCellAccessoryNone];
[tableAlert.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
}
- (void)tableAlert:(SBTableAlert *)tableAlert didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"Dismissed: %i", buttonIndex);
}
我收到的错误消息是:
2013-04-25 00:13:35.389 MyTestProject[3386:c07] *** -[SBTableAlert tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x682ed80
但是我不知道如何跟踪或调试它。看来它可能与 ARC 有关,因为演示项目不使用它,但我无法确定如何解决这个问题。
任何帮助表示赞赏!