2012-02-20 69 views

回答

1

我建議在UITableViewCell中使用標籤屬性。

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;    
// returns nil if cell is not visible or index path is out of range 
{ 

    static NSString *identifier = @"MyIndetifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    //make sure tu put here, or before return cell. 
    cell.tag = 0; //0 =NO, 1=YES; 

    return cell; 
} 

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    BOOL boolean = cell.tag; // return 0 or 1. based on what boolean you set on this particular row. 
} 
0

您可能還有其他一些存儲空間,您可以在其中存儲表格單元格標題或副標題等內容。在那裏存儲布爾值。使用它來將bool轉換爲可以放入數組或字典中的東西。

[NSNumber numberWithBool:YES] 

例如,如果你使用的字符串NSArray存儲的標題,而不是使用字典的數組。每個字典都有一個「標題」和(例如)「isActive」布爾值(存儲爲NSNumber)。

0

NSMutableArray * tableData;

每個表格單元格都與tableData中的一個NSMutableDictionary存儲相關聯,您可以將一個NSNumber(存儲布爾)設置爲Dictionary。

2

有這麼多的方法:
1.您可以使用UITableViewCell.tag財產
2.您可以創建自己的電池類從繼承的UITableViewCell並添加有正常的財產爲您bool值
3.您可以使用與您的tableview關聯數組,當你選擇單元格,只需使用indexPath陣列中找到相關的價值

0

你需要實現的UITableView

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;    
// returns nil if cell is not visible or index path is out of range 
{ 
//create cell here 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    return cell; 
} 
的方法
  • (無效)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath { //使用indexpath.row可以訪問在其上用戶點擊的細胞。 }