eXit_door 2013-08-19 06:09 采纳率: 0%
浏览 3017
已采纳

UItableViewCell中调用视图

有六个文件:

LeftPanelViewController.h
LeftPanelViewController.m
LeftPanelViewController.xib
ForecastViewController.h
ForecastViewController.m
ForecastViewController.xib

在LeftPanelViewController.xib 中有一个视图,其中包含表视图。
我要设置LeftPanelViewController.xib中的一个表视图的cell。实现按下cell就可以调用
ForecastViewController.xib中的视图。

LeftPanelTableViewController.m代码:

#import "LeftPanelViewController.h"
#import "ForecastViewController.h"
@interface LeftPanelViewController ()

@property (nonatomic, weak) IBOutlet UITableView *myTableView;
@property (nonatomic, weak) IBOutlet UITableViewCell *cellMain;
@property (copy, nonatomic) NSArray *MRP;

@end

@implementation LeftPanelViewController

- (void)viewDidLoad
{
[super viewDidLoad];

Array = [[ NSMutableArray alloc] init];
[Array addObject:@"Forecast"];
[Array addObject:@"Inventory"];

}

- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [Array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:SimpleTableIdentifier];

//add an image to the tablecell
UIImage *image = [UIImage imageNamed:@"Icon.png"];
cell.imageView.image = image;

}
cell.textLabel.text = [Array objectAtIndex:indexPath.row];

if (indexPath.row < 7) {
cell.detailTextLabel.text = @"Account";
} else {
cell.detailTextLabel.text = @"Settings";
}
return cell;
}

- (void)viewDidUnload
{
[super viewDidUnload];
}
#pragma mark -
#pragma mark View Will/Did Appear
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}

#pragma mark -
#pragma mark View Will/Did Disappear
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
#pragma mark -
#pragma mark Array Setup
#pragma mark -
#pragma mark UITableView Datasource/Delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
#pragma mark -
#pragma mark Default System Code

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[Array objectAtIndex:indexPath.row] isEqual:@"Forecast"]) {
ForecastViewController *Forecast = [[ ForecastViewController alloc] initWithNibName:@"ForecastViewController" bundle:nil];
[self.navigationController pushViewController:Forecast animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
  • 写回答

1条回答 默认 最新

  • Chengzi_963 2013-08-19 08:56
    关注

    不要用:

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

    使用:

    [self presentViewController:Forecast animated:YES completion:nil];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!