2010-07-16 84 views
2

由于某种原因,这个UITableView不断崩溃,它似乎像UITableView无法显示secondsString由于某种原因,但我不知道为什么...请帮我在这里因为我不知道我可以是做错了.....谢谢!TableView崩溃

#import "SettingsView.h" 

@implementation SettingsView 

- (void)viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:animated]; 
    transmissionSetup = [[TransmissionSetupViewController alloc]  initWithNibName:@"TransmissionSetupViewController" bundle:nil]; 
    transmissionSetup.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    NSLog(@"%i", [self getMinutes]); 
    [self setSeconds:10]; 
    secondsString = [NSString stringWithFormat:@"%i", [self getSeconds]]; 
    [self.tableView reloadData]; 
} 

#pragma mark Table view methods 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if (indexPath.section == 0) { 
     cell.textLabel.text = @"Every:"; 
     cell.detailTextLabel.text = secondsString; 
    } 
    // Set up the cell... 

    return cell; 
} 

@end 
+0

你在控制台看到什么错误? – 2010-07-16 12:15:37

+0

2010-07-16 14:16:28.864 Navex [31130:207] 0 编程接收信号:“EXC_BAD_ACCESS”。 这是我得到的错误 – 2010-07-16 12:16:53

+0

我删除了与您的问题无关的部分代码 - 请尽量避免发布不必要的代码,以便更容易地帮助您 – Vladimir 2010-07-16 12:22:59

回答

1

您初始化secondString具有自动释放的字符串 - 因此它不能保证,这将是目前的范围之内有效。您需要在初始化时保留它(并且不要忘记稍后再发布)

我建议您查看objective-c properties以访问ivars。

+0

我在我的头文件中初始化它,如下所示:NSString * secondsSTring ; 如何在初始化时保留它? – 2010-07-16 12:24:59

+0

好吧我知道了非常感谢你! – 2010-07-16 12:28:11

0
// try this 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
} 

if (indexPath.section == 0) { 
    cell.textLabel.text = @"Every:"; 
    cell.detailTextLabel.text = secondsString; 
} 
// Set up the cell... 

return cell; 
}