如何在UITableview的每一行中存儲布爾值。我需要檢索存儲在單元格中的布爾值,當該特定單元格被選中時。在UITableviewcell中存儲布爾值
0
A
回答
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可以訪問在其上用戶點擊的細胞。 }
相關問題
- 1. 存儲布爾值
- 2. 在Android中存儲多個布爾值
- 3. 在SQL中存儲布爾值?
- 4. 如何將布爾值存儲到NSArray?
- 5. 布爾值沒有正確存儲?
- 6. 存儲布爾值:捆綁還是單獨存儲?
- 7. 更改存儲在數組中的對象的布爾值
- 8. 如何更新在GAE數據存儲中的布爾值?
- 9. 在表單處理的隱藏字段中存儲布爾值
- 10. 我應該如何在mongodb中存儲布爾值?
- 11. 什麼是在MySQL中存儲布爾值的數據類型?
- 12. 取消存儲在NSNumber中的布爾值
- 13. 如何將一組布爾值存儲在MySql數據庫中?
- 14. 有多少個字節用於在Java中存儲布爾值?
- 15. NSPredicate - 基於布爾值存儲值篩選值
- 16. 布爾索引的列值存儲爲一個變量在python
- 17. 在服務器上存儲一個布爾值
- 18. SharedPreferences不保存布爾值
- 19. 調用存儲過程,傳遞NULL值,處理布爾值
- 20. vb6集合存在和布爾值集
- 21. Container中的寄存器布爾值
- 22. 布爾值與tinyint(1)在MySQL中的布爾值
- 23. 在德爾福存儲一組數值
- 24. 是否有可能存儲在Java中的字符串中的布爾值
- 25. 在UITableViewCell中存儲唯一ID
- 26. Bash比較存儲的「布爾」值與什麼?
- 27. 從T-SQL存儲過程返回布爾值
- 28. 寫整數值不布爾到存儲器字100
- 29. 爲什麼Stata將布爾值存儲爲float?
- 30. 檢查布爾返回值pdo的mysql存儲函數