首先,我才刚刚开始开发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有关,因为演示项目没有使用它,但我无法确定如何修复它。
感谢您的帮助!