我試圖使用幾個不同的重用標識符,讓用戶能夠輸入數據沒有segue ...(只是覺得它會很好)。爲什麼沒有(cell == nil)工作?
這是我第一次嘗試:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(addC && indexPath.row == 0 && indexPath.section == 0){
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
UITextField *txtField = [[UITexField alloc] initWithFrame:CGRectMake(10, 7, 260, 30);
[cell addsubview:txtField];
cell.txtField.delegate = self;
cell.txtField.text = nil;
return cell;
不過,我注意到,如果我使用的字段不止一次文本字段會重複,留下舊值下方。 因此,一些reasearch後,我說:
if(cell == nil){
}
圍繞txtField初始化,但它不會開火。我結束瞭解決此問題的工作完全由製作一個單獨的UITableViewCell類,但現在我想補充 SWTableViewCell 和改變從我的UITableViewCell小區到CustomTableViewCell。附加到我的表和初始化
這種定製的實用程序需要使用
if (cell == nil) {
NSMutableArray *leftUtilityButtons = [NSMutableArray new];
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]
icon:[UIImage imageNamed:@"check.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:1.0f blue:0.35f alpha:1.0]
icon:[UIImage imageNamed:@"clock.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0]
icon:[UIImage imageNamed:@"cross.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.55f green:0.27f blue:0.07f alpha:1.0]
icon:[UIImage imageNamed:@"list.png"]];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0]
title:@"More"];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
title:@"Delete"];
cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier
containingTableView:_tableView // For row height and selection
leftUtilityButtons:leftUtilityButtons
rightUtilityButtons:rightUtilityButtons];
cell.delegate = self;
}
如果還沒有實現這個插件,但是當我研究我的問題,現在我還沒有發現任何東西之前。
我也曾嘗試
if (cell.contentView == nil)
if (cell.contentView.subViews == nil)
if (cell.subViews == nil)
,但由於某種原因,將不會觸發第一次像它應該。我究竟做錯了什麼?
如果我可以投票你,我會多數民衆贊成正是我是如何解決我的第一個問題,但接着下一個,如果你看看他使用的SWTableViewCell if(cell == nil)複製那個。因爲它不會被稱爲ID必須翻拍他的整個項目幾乎使用它? theres暫時沒有解決方法 – Snymax
只需將代碼放入'initWithStyle:reuseIdentifier:'我將編輯我的答案並舉例說明如何工作。 – Dima
試圖模擬這個後,它看起來像默認的'SWTableViewCell'初始值設定程序期望引用'UITableView',這是不容易從該點訪問。因此,我會建議擺脫註冊的單元格,而是結構化代碼以允許手動初始化單元格,就像他們的文檔中的代碼示例一樣。 – Dima