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'等在哪里获得它们的值? –