我是IOS新手,我有一個UITableview中有三個按鈕,當我選擇按鈕圖像會改變。我的問題是:如何將圖像存儲在表格視圖中,當我退出應用程序並再次回到應用程序時意味着所選圖像應該在那裏。我怎麼能做到這一過程,任何人都可以幫助我。如何在UITableview中存儲UIButton圖像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
CustomizedCellView *cell = (CustomizedCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [table dequeueReusableHeaderFooterViewWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomizedCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(80, 27, 36, 36);
[button1 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"l"ofType:@"png"]] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"lblue.png"]
forState:UIControlStateSelected];
[button1 addTarget:self action:@selector(radiobtn4:) forControlEvents:UIControlEventTouchUpInside];
button1.tag=1;
[cell.contentView addSubview:button1];
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(160, 27, 36, 36);
[button2 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"e"ofType:@"png"]] forState:UIControlStateNormal];
[button2 setImage:[UIImage imageNamed:@"eblue.png"]
forState:UIControlStateSelected];
[button2 addTarget:self action:@selector(radiobtn4:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button2];
button2.tag=3;
button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(240, 27, 36, 36);
[button3 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"v"ofType:@"png"]] forState:UIControlStateNormal];
[button3 setImage:[UIImage imageNamed:@"vblue.png"]
forState:UIControlStateSelected];
[button3 addTarget:self action:@selector(radiobtn4:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button3];
button3.tag=2;
- (void)radiobtn4:(UIButton *)sender
{
UITableViewCell *cell=(UITableViewCell *)sender.superview;
if(sender.selected == NO)
{
if(sender.tag==1){
UIButton *otherButton=(UIButton *)[cell viewWithTag:1];
otherButton.selected=YES;
UIButton *other=(UIButton *)[cell viewWithTag:2];
other.selected=NO;
}else if(sender.tag==2){
UIButton *otherButton=(UIButton *)[cell viewWithTag:2];
otherButton.selected=YES;
UIButton *other=(UIButton *)[cell viewWithTag:1];
other.selected=NO;
} else if(sender.tag == 3)
{
UIButton *otherButton=(UIButton *)[cell viewWithTag:3];
otherButton.selected=YES;
}
} else if(sender.selected == YES)
{
if(sender.tag==1){
UIButton *otherButton=(UIButton *)[cell viewWithTag:1];
[otherButton setImage:[UIImage imageNamed:@"l.png"]
forState:UIControlStateNormal];
otherButton.selected=NO;
}else if(sender.tag==2){
UIButton *otherButton=(UIButton *)[cell viewWithTag:2];
[otherButton setImage:[UIImage imageNamed:@"v.png"]
forState:UIControlStateNormal];
otherButton.selected=NO;
} else if(sender.tag == 3)
{
UIButton *otherButton=(UIButton *)[cell viewWithTag:3];
[otherButton setImage:[UIImage imageNamed:@"e.png"]
forState:UIControlStateNormal];
otherButton.selected=NO;
}
}
}
上面是我的編碼。
使用數據庫或plist中存儲你的選擇.. – iphonic 2015-03-13 09:52:19
主要標誌陣列/字典你逝去/使用 – the1pawan 2015-03-13 09:56:57