首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将UITableView推送到UITableView

将UITableView推送到UITableView
EN

Stack Overflow用户
提问于 2013-08-11 23:59:40
回答 1查看 501关注 0票数 0

我似乎不能推到另一个UITableView。当我运行代码时,它只显示EventType,单击后,它会发送push到另一个UITableView,显示事件。代码应该将一个UITableView推送到另一个UITableView。有人能帮我解决这个问题吗?我认为这是来自RootViewController,但我似乎无法确定问题的所在。

应用程序工作正常,但我不能推到另一个TableViewController。下面是代码used.Here是使用的代码,但是它并没有显示出太多信息,因为大多数设置都是使用IB完成的。

我是RootViewController.m ,我认为问题来自于这个问题,但我似乎无法从哪里找到答案。

代码语言:javascript
复制
#import "RootViewController.h"
#import "EventTypeViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController
@synthesize eventType;



- (void) viewDidLoad
{
    eventType = [[NSMutableArray alloc]init];
    [eventType addObject:@"Corporate"];
    [eventType addObject:@"Social"];
    [eventType addObject:@"Dining"];
    [self setTitle: @"Events"];



}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [eventType count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];


         cell.textLabel.text = [[eventType objectAtIndex:indexPath.row]retain];
         [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

        return cell;


    }


}

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

{

    EventTypeViewController *events = [[EventTypeViewController alloc] initWithNibName:@"EventTypeViewController" bundle:nil];

    if ([[eventType objectAtIndex:indexPath.row] isEqual:@"Corporate"])
    {
        events.eventsInt = 0;
        [events setTitle:[eventType objectAtIndex:indexPath.row]];
    }

    if ([[eventType objectAtIndex:indexPath.row] isEqual:@"Social"])
    {
        events.eventsInt = 1;
        [events setTitle:[eventType objectAtIndex:indexPath.row]];
    }

    if ([[eventType objectAtIndex:indexPath.row] isEqual:@"Dining"]) {
        events.eventsInt = 2;
        [events setTitle:[eventType objectAtIndex:indexPath.row]];
    }

    [self.navigationController pushViewController:events animated:YES];

}

@end

我是EventTypeViewController.m -我对此没什么好说的。

代码语言:javascript
复制
#import "EventTypeViewController.h"

@interface EventTypeViewController ()

@end

@implementation EventTypeViewController

@synthesize eventsInt;


- (void)viewDidLoad
{

    corporateArray = [[NSMutableArray alloc]
                      initWithObjects:@"Corporate 1", @"Corporate 2", @"Corporate 3", @"Corporate 4", nil];
    socialArray = [[NSMutableArray alloc]
                   initWithObjects:@"Social 1", @"Social 2", nil];
    diningArray = [[NSMutableArray alloc]
                   initWithObjects:@"Dining 1", @"Dining 2", @"Dining 3", nil];


}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (eventsInt == 0)
        return [corporateArray count];
    if (eventsInt == 1)
        return [socialArray count];
    if (eventsInt == 2)
        return [diningArray count];

    [self.tableView reloadData];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]autorelease];
    }

    // Configure the cell...
    if (eventsInt == 0)
        cell.textLabel.text = [[corporateArray objectAtIndex:indexPath.row]retain];
    if (eventsInt == 1)
        cell.textLabel.text = [[socialArray objectAtIndex:indexPath.row]retain];
    if (eventsInt == 2)
        cell.textLabel.text = [[diningArray objectAtIndex:indexPath.row]retain];

    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

    return cell;
}

@end
EN

回答 1

Stack Overflow用户

发布于 2013-08-12 03:54:59

您的UITableViewController是否嵌入了UINavigationController?这样您就可以激活push方法。

你也可以使用辅助装置。实现-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender,为下一个控制器设置数据变量,并使用[self performSegueWithIdentifier:(NSString *) sender:(id)sender]推送

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18177910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档