我的問題是,當單元格被點擊時,是否可以獲取文本數據並從php的ViewController中讀取它?UITableView - 點擊時獲取數據
我猜didSelectRowAtIndexPath
是做到這一點的關鍵,但我不知道如何寫。
我可以從php獲取數據到我的TableViewController
,如下所示;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [json count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *info = [json objectAtIndex:indexPath.row];
cell.textLabel.text = [info objectForKey:@"Artist"];
cell.detailTextLabel.text = [info objectForKey:@"Song"];
return cell;
}
是的,它是可能的用途做了選擇方法,並在方法編寫retrive數據的代碼,只有陣列之前,如果你想在刷新你的tableview或撥打新的視圖控制器,並通過它在那裏。 – vishiphone