我是iPhone開發的新手。我已經創建了一個UITableView
。我已將所有內容接通,包括delegate
和datasource
。但是,我不想通過使用UITableViewCellAccessoryDetailClosureButton
來添加詳細視圖附件,而是想點擊UITableViewCell
,它應該導致另一個視圖,其中包含有關UITableViewCell
的更多詳細信息。 我的視圖控制器看起來是這樣的:點擊TableView會引導您到另一個視圖
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
NSArray *tableItems;
NSArray *images;
}
@property (nonatomic,retain) NSArray *tableItems;
@property (nonatomic,retain) NSArray *images;
@end
ViewController.m
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController()
@end
@implementation ViewController
@synthesize tableItems,images;
- (void)viewDidLoad
{
[super viewDidLoad];
tableItems = [[NSArray alloc] initWithObjects:@"Item1",@"Item2",@"Item3",nil];
images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"clock.png"],[UIImage imageNamed:@"eye.png"],[UIImage imageNamed:@"target.png"],nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return tableItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Step 1:Check whether if we can reuse a cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//If there are no new cells to reuse,create a new one
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
UIView *v = [[UIView alloc] init];
v.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = v;
//changing the radius of the corners
//cell.layer.cornerRadius = 10;
}
//Set the image in the row
cell.imageView.image = [images objectAtIndex:indexPath.row];
//Step 3: Set the cell text content
cell.textLabel.text = [tableItems objectAtIndex:indexPath.row];
//Step 4: Return the row
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
cell.backgroundColor = [ UIColor greenColor];
}
@end
需要一些這方面的指導..謝謝..請原諒我,如果這是一個愚蠢的題。
哪裏你_dataSource和DetailViewController從何而來? – lakesh
這僅僅是一個例子。在你的情況下,self.tableItems將是數據源,DetailViewController將是你的UIViewController的名字,你將用它來呈現你的詳細信息視圖。 –
DetailViewController將是您的UIViewController的名稱,您將使用它顯示您的詳細信息視圖。這意味着我需要另一個ViewController,我有權這麼說嗎?例如,SecondViewController? – lakesh