0
我有一個XCode項目,並在我的一個視圖控制器中將JSON從MySQL數據庫解析到表格視圖中。該應用程序是一個可幫助您制定學校時間表的應用程序。我想要做的是,當用戶點擊表格視圖中的一個單元格時,會彈出一個UIAlertView,並讓他們選擇將來自學校的課程添加到另一個表格視圖中,導致他們開始構建他們的時間表。這是我的一些代碼。JSON /表格視圖/ UI AlertView
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"detailCell";
// ClassDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
ClassDetailCell *cell = (ClassDetailCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ClassDetailCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
switch (indexPath.section) {
case 0:
cell.theLabel.text = nameString;
cell.detailLabel.text = @"Course Name";
break;
case 1:
cell.theLabel.text = teacher;
cell.detailLabel.text = @"Teacher";
break;
case 2:
cell.theLabel.text = location;
cell.detailLabel.text = @"Bulding & Room";
break;
case 3:
cell.theLabel.text = date;
cell.detailLabel.text = @"Date";
break;
case 4:
cell.theLabel.text = days;
cell.detailLabel.text = @"Days";
break;
case 5:
cell.theLabel.text = timeString;
cell.detailLabel.text = @"Time";
break;
case 6:
cell.theLabel.text = crn;
cell.detailLabel.text = @"CRN";
break;
case 7:
cell.theLabel.text = [addCLlass objectAtIndex:indexPath.row];
cell.detailLabel.text = @"Fall or Spring";
break;
default:
break;
}
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"classdetailcell.png"]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add This Class To Your Schedule?" message:@"Go Ahead!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"No Thanks!", nil];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"OK"])
{
}
else if([title isEqualToString:@"No Thanks!"])
{
[self dismissModalViewControllerAnimated:YES];
}
}
我能夠讓UIAlertView在didSelectRowAtIndexPath方法中彈出。當用戶點擊「不,謝謝!」風險投資正常解僱。現在,當他們點擊確定時,我希望課程的名稱可以放在另一個表格視圖中。在放入其他表視圖後,我希望用戶能夠從其他表視圖中添加類,刪除類等。我也希望將時間表保存到設備中。
建議將是偉大的!
您的數據模型現在看起來像什麼? 'nameString','teacher'等在哪裏獲得它們的值? –