2009-10-08 23 views
0

這是我的代碼的一部分。當我嘗試加載包括uitableview的視圖時,我的應用程序崩潰。 我認爲我嘗試使用但沒有找到它的表有問題。 幫助,請宣佈的.hiPhone的SDK - 的UITableView - 不能在表分配表視圖

gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil]; 

NSArray *gameTimingTable; 這是我使用表中分配給UITableView的

- (void)viewDidLoad { 

gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil]; 



} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // There is only one section. 
    return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of time zone names. 
    return [gameTimingTable count]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *MyIdentifier = @"MyIdentifier"; 

    // Try to retrieve from the table view a now-unused cell with the given identifier. 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    // If no cell is available, create a new one using the given identifier. 
    if (cell == nil) { 
     // Use the default cell style. 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; 
    } 

    // Set up the cell. 
    NSString *cadence = [gameTimingTable objectAtIndex:indexPath.row]; 
    cell.textLabel.text = cadence; 

    return cell; 
} 

/* 
To conform to Human Interface Guildelines, since selecting a row would have no effect (such as navigation), make sure that rows cannot be selected. 
*/ 
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    return nil; 
} 

非常感謝

+0

任何想法? ....................... thanx – kossibox 2009-10-08 13:52:17

回答

0

這裏的問題的代碼可能有兩件事情之一(或兩者):

1 ...你是從willSelectRowAtIndexPath實現方法具返回nil d。如果您不讓用戶能夠點擊單元格,則不要重寫此方法,即不要觸摸它。伴隨着的是,cellForRowAtIndexPath方法中,你可以做:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

,以確保當用戶點擊它的細胞甚至不突出。

2 ...你已經初始化數組gameTimingTable的方式意味着你已經創造了它之後,所以它不能在代碼的其他地方訪問它會被自動釋放。初始化它使用下列方法代替:

gameTimingTable=[[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil] retain]; 

// OR ... 

gameTimingTable=[[NSArray alloc] initWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil]; 

......但記得要釋放數組中的dealloc方法:

- (void)dealloc { 
[gameTimingTable release]; 
[super dealloc]; 

}