まず、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 を使用していないため、ARC と関係があるようですが、これを修正する方法を特定することはできません。
どんな助けでも大歓迎です!