我有UITableView,其中如果任何行被選中,我正在存儲一些值。如果任何其他行被選中,我正在顯示一個alertView,並警告他之前的選擇將會消失。這個alerView有2個按鈕YES和NO。如果選擇YES,請繼續選擇新的行。但是,如果沒有被選中,我想重新選擇前一行。如果提問,我可以發佈代碼。但似乎更多的是邏輯問題而不是面向代碼。最後選擇行在UITableView
謝謝。
我有UITableView,其中如果任何行被選中,我正在存儲一些值。如果任何其他行被選中,我正在顯示一個alertView,並警告他之前的選擇將會消失。這個alerView有2個按鈕YES和NO。如果選擇YES,請繼續選擇新的行。但是,如果沒有被選中,我想重新選擇前一行。如果提問,我可以發佈代碼。但似乎更多的是邏輯問題而不是面向代碼。最後選擇行在UITableView
謝謝。
第一家門店點擊的tableview指數在UITableView Delegate
像下面的全局變量,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView==yourTableview) {
yourMemberVariable=[indexPath row];
}
}
然後檢查yourMemberVariable
in UIAlertView delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0)//OK button pressed
{
//do something
}else{
if(yourMemberVariable>someValue){ //perform your own conditions whatever
[myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:yourMemberVariable inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
}
}
}
跟蹤上次選擇的項目。在表格的選擇委託上,存儲在通過班級訪問的變量中選擇的內容。
NSInteger selectedRow = 0;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedRow = [indexPath row];
}
現在,你知道,如果在UIAlertView中代表按NO選擇什麼元素
[myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:selectedRow inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
那麼你的問題是什麼? – CarlJ
我如何獲得最後選擇的行? – LeXeR