的工作如何選擇幾個UITableViewCell
(如複選標記,但我自己的風格),然後做選擇的項目的東西嗎?一些的UITableViewCell
作爲一個對號(或別的東西),我想用UIImageView
:
的工作如何選擇幾個UITableViewCell
(如複選標記,但我自己的風格),然後做選擇的項目的東西嗎?一些的UITableViewCell
作爲一個對號(或別的東西),我想用UIImageView
:
- (空)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone)
{
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
for(int i=0;i<[Array count];i++)
{
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
}
現在試試......
要添加到Pandu1251's answer,如果要使用自己的複選標記圖像,可以設置自定義附件視圖並遵循他指定的相同邏輯。
要設置自定義配件來看,使用
我認爲這是我需要的......如何將我的UIImageView與cell.accessoryView連接起來? – Romowski 2013-03-06 11:38:06
用你的圖像創建一個UIImageView對象,然後將accessoryView設置爲你的圖像視圖(即用你的imageview的變量名稱替換myAccessoryView) – lostInTransit 2013-03-06 12:05:24
只是做如下。爲此,你必須採取NSMutableArray。我在這裏採取了arrMethodsToBeStored。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.textLabel.textColor=[UIColor darkGrayColor];
cell.textLabel.font= [UIFont fontWithName:@"Arial Rounded MT Bold" size:15.0];
Scope_RepairMethod *scpObj=[repairMethodArr objectAtIndex:indexPath.row];
cell.textLabel.text= scpObj.strRepairMethod;
if([self.checkedIndexPath isEqual:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSString *selID;
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
Scope_RepairMethod *scpObj=[repairMethodArr objectAtIndex:indexPath.row];
if (newCell.accessoryType == UITableViewCellAccessoryNone)
{
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
[arrMethodsToBeStored addObject:scpObj.strRepairMethod];
}
else
{
newCell.accessoryType = UITableViewCellAccessoryNone;
[arrMethodsToBeStored removeObject:scpObj.strRepairMethod];
}
NSLog(@"selected method arr==== %@",arrMethodsToBeStored);
// I want to enable my save button only if one or more values from table are selected
if(arrMethodsToBeStored.count > 0)
saveBtn.enabled=true;
else
{
saveBtn.enabled=false;
}
}
...我想檢查不僅一個單元格,但幾個(如上面的屏幕上) – Romowski 2013-03-06 11:12:03
現在它工作正常!謝謝!我可以把我的UIImageView而不是檢查標誌(如在屏幕上 - 十字線)? – Romowski 2013-03-06 11:31:46