2012-06-24 59 views
0

我想從前3小時中找出這個錯誤。通過搜索,我已經知道這個錯誤與內存管理有關,但是我沒有弄清楚我做錯了什麼。nscfstring文本無法識別的選擇器發送到實例

我已經把這些4個標籤:

@interface InteractiveHistory : UITableViewController { 
UILabel *date; 
UILabel *startTime; 
UILabel *cal; 
UILabel *duration; 
} 

然後創建的屬性和合成它們。在viewDidLoad中,我初始化此相似的:

date = [[UILabel alloc] init]; 

我也有釋放的dealloc他們()方法。

我想要做的就是使用這4個標籤在表格的單元格中寫入一些文本。文本將取決於indexPath。

在的cellForRowAtIndexPath方法,只是顯示你2個標籤,並指出錯誤行:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

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

     NSLog(@"constructing cell"); 

     //set up labels text 

     date = [NSString stringWithFormat:@"%@",[[int_data objectAtIndex:indexPath.row] objectForKey:@"Date"]]; 


NSLog(@"%@",date.text); //App crashes at this line 
     [date setTag:1]; 


     startTime = [NSString stringWithFormat:@"%@",[[int_data objectAtIndex:indexPath.row] objectForKey:@"Start Time"]]; 

     //setting tag and position of label 
     [startTime setTag:2]; 
     CGRect labelpos = startTime.frame; 
     labelpos.origin.y = date.bounds.size.height + 2; 
     startTime.frame = labelpos; 

     NSLog(@"labels set"); 

    // Configure the cell... 
    [[cell contentView] addSubview:date]; 
    [[cell contentView] addSubview:startTime]; 
    [[cell contentView] addSubview:duration]; 
    [[cell contentView] addSubview:cal]; 


    NSLog(@"A cell set"); 

    }  

    return cell; 
} 

任何人可以PLZ告訴我,我究竟做錯了什麼?我希望我的問題是明確的..

回答

9

行:

date = [NSString stringWithFormat:@"%@",[[int_data objectAtIndex:indexPath.row] objectForKey:@"Date"]]; 

應該是:

date.text = [NSString stringWithFormat:@"%@",[[int_data objectAtIndex:indexPath.row] objectForKey:@"Date"]]; 

否則你date指針設置爲一個NSString的實例,而不是設置它的內容。

編輯:

由於DANH正確地指出,你也會有同樣的問題與startTime

+0

+1與startTime相同。 – danh

+0

謝謝你解決了我的問題。即使一秒鐘,它也不會出現在我的腦海裏,它可能是一個如此愚蠢的錯誤。謝謝。並且@你的觀點是絕對正確的。 – NightFury

+0

沒問題 - 我們都做到了! – jrtc27

相關問題