我是iOS新手,遇到問題時嘗試將值從TableView傳回到主控制器。respondsToSelector:不適用於委託
,我的工作對這種情況的出現
- 家庭控制器上有一個按鈕
- 點擊按鈕,打開第二UIViewController中的項目清單
- 用戶從列表
- 選擇一個項目選定的項目被添加到家庭控制器上的另一個列表
真的很感謝任何指針,這是蘇:
這是我正在準備Segue公司家用
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destination = segue.destinationViewController;
if ([destination respondsToSelector:@selector(setDelegate:)]) {
[destination setValue:self forKey:@"delegate"];
}
}
SecondController有代表的ID,所以我假設委託設置爲「respondsToSelector
」返回「setDelegate」
現在,SecondController當用戶選擇一個項目我打電話didSelectRowAtIndexPath
& viewWillDisappear
方法來設置項目,使視野中消失:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
POSAllItemsCell *cell = (POSAllItemsCell *) [tableView cellForRowAtIndexPath:indexPath];
item = [NSDictionary dictionaryWithObjectsAndKeys:cell.name, @"Name", cell.price, @"Price", cell.code, @"Code", nil];
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([delegate respondsToSelector:@selector(setSelection:)]) {
[delegate setValue:item forKey:@"selection"];
}
}
現在,這裏的問題是,對於respondsToSelector
回報setSelection
虛假的,即使我有我的HomeController爲setSelection方法:提前
- (void) setSelection:(NSDictionary *)dict {
if (![dict isEqual:selection]) {
......
}
}
道歉,如果我在不清晰的問題,或者格式不正確。順便說一句,這是爲iOS 5和Xcode 4.2
顯示你如何宣佈「家」視圖控制器的委託。 – omz 2013-04-26 21:59:14
嗯,我可能在這裏錯過了一些東西,但我認爲在應用程序啓動時爲我創建了代理「自動」。這是我如何在「第二個」控制器中聲明的:@property(weak,nonatomic)id delegate; – Vivek 2013-04-26 22:04:27
如果您登錄委託,它是否爲零? – rdelmar 2013-04-26 22:05:09