0
  1. 我的应用程序有 UITableViewController 和 DetailViewController。
  2. UITableViewController 具有多单元选择和详细附件按钮。
  3. 如果用户选择多个单元格并点击 TOTAL Button Alert 消息,则会显示课程总价格。
  4. 如果用户点击 Detail 附件按钮,它会转到 DetailViewController。

好的,现在我的问题是我怎么能用我的代码做到这一点:

UITableViewController.m

    - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
        [self configureCell:cell atIndexPath:indexPath];

        return cell;


    }


    - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
    {
        NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
        cell.textLabel.text = [[object valueForKey:@"courseCode"] description];
        cell.detailTextLabel.text = [[object valueForKey:@"courseName"] description];

    }

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {

        if ([[segue identifier] isEqualToString:@"showDetail"]) {
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
            [[segue destinationViewController] setDetailItem:object];
        }            
    }

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{



}


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {

        NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];


        if ([[[object valueForKey:@"creditHours"] description]isEqualToString: @""]) {

        }
        //some thing doing if the user deselect the cell..



    }

    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
    {

        NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];

        if ([[[object valueForKey:@"creditHours"] description]isEqualToString: @""]) {

        }

        //some thing doing if the user deselect the cell..

    }

    - (IBAction)doneButton:(id)sender {

        given the total...

    }

DetailViewController.h

@property (strong, nonatomic) id detailItem;

@property (weak, nonatomic) IBOutlet UITextField *courseCodeLabel;
@property (weak, nonatomic) IBOutlet UITextField *courseNameLabel;
@property (weak, nonatomic) IBOutlet UITextField *creditHoursLabel;
@property (weak, nonatomic) IBOutlet UITextField *preRequisitesLabel;
@property (weak, nonatomic) IBOutlet UITextField *coursePriceLabel;
@property (weak, nonatomic) IBOutlet UITextField *courseEPPLabel;
@property (weak, nonatomic) IBOutlet UITextView *courseDetailLabel;

细节视图控制器.m

@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

@synthesize detailItem = _detailItem;
@synthesize courseCodeLabel = _courseCodeLabel;
@synthesize courseNameLabel = _courseNameLabel;
@synthesize creditHoursLabel = _creditHoursLabel;
@synthesize preRequisitesLabel = _preRequisitesLabel;
@synthesize coursePriceLabel = _coursePriceLabel;
@synthesize courseEPPLabel = _courseEPPLabel;
@synthesize courseDetailLabel = _courseDetailLabel;


#pragma mark - Managing the detail item



- (void)setDetailItem:(id)newDetailItem
{
    [self configureView];

    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;

        // Update the view.
        [self configureView];
    }
}

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {
        self.courseCodeLabel.text = [[self.detailItem valueForKey:@"courseCode"] description];
        self.courseNameLabel.text = [[self.detailItem valueForKey:@"courseName"] description];
        self.creditHoursLabel.text = [[self.detailItem valueForKey:@"creditHours"] description];
        self.preRequisitesLabel.text = [[self.detailItem valueForKey:@"preRequisites"] description];
        self.coursePriceLabel.text = [[self.detailItem valueForKey:@"coursePrice"] description];
        self.courseEPPLabel.text = [[self.detailItem valueForKey:@"courseEPP"] description];
        self.courseDetailLabel.text = [[self.detailItem valueForKey:@"courseDetails"] description];

    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self configureView];
}

请注意,segue 以正常方式运行良好。

4

1 回答 1

0

我认为目前您的 segue 将 tableview 单元(该原型)与您的详细控制器链接。您可以尝试将 tableview 控制器本身(即整个事物)与您的详细控制器链接。(只需从 tableview 控制器的底部按 ctrl 拖动即可)

然后你-prepareForSegue像往常一样处理你的方法,但你需要调用-performSegue才能真正触发 segue。点击单元格将无效。因此,在您的-tableView:tableViewaccessory....方法中,您可以调用performSegue进行导航,并根据需要处理您的didSelectRow..方法。

于 2012-08-18T20:01:21.030 回答