我想在一個利用ARC的項目中創建一個簡單的UItableview應用程序。表格呈現得很好,但如果我嘗試滾動或點擊一個單元格,應用程序崩潰。滾動或點擊UITableView崩潰 - 問題與ARC?
望着NSZombies(是正確的方法說?)我得到的消息「 - [PlacesViewController respondsToSelector:]:消息發送到釋放實例0x7c29240」
我相信這事做與ARC,因爲我過去成功實現了UItableviews,但這是我第一個使用ARC的項目。我知道我必須錯過一些非常簡單的事情。
PlacesTableViewController.h
@interface PlacesViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *myTableView;
@end
PlacesTableViewController.m
#import "PlacesTableViewController.h"
@implementation PlacesViewController
@synthesize myTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.myTableView.dataSource = self;
self.myTableView.delegate = self;
[self.view addSubview:self.myTableView];
}
#pragma mark - UIViewTable DataSource methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *result = nil;
static NSString *CellIdentifier = @"MyTableViewCellId";
result = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(result == nil)
{
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
result.textLabel.text = [NSString stringWithFormat:@"Cell %ld",(long)indexPath.row];
return result;
}
@end
我們可以獲取用於alloc,init和存儲PlacesViewController的代碼嗎? – hukir 2012-10-16 19:02:30