程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-UItableViewCell中調用視圖

ios-UItableViewCell中調用視圖

編輯:編程綜合問答
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

最佳回答:


不要用:

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

使用:

[self presentViewController:Forecast animated:YES completion:nil];
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved