ios开发中segment来回切换tablcell imageview 点击cell怎么实现点击

UISegmentedControl的用法
1。在.m文件中写入:
@interface ViewController (){
UISegmentedControl *segmentC
& & UILabel
@property (retain,
nonatomic) IBOutlet UITableView
@property(nonatomic,retain)
IBOutlet UISegmentedControl
@property(nonatomic,retain)
IBOutlet UILabel *segL
-(IBAction)segmentIndexC
@implementation ViewController
@synthesize dataV
@synthesize segmentC
@synthesize segL
-(IBAction)segmentIndexChanged&
(self.segmentControl.selectedSegmentIndex)
segLabel.text=@"seg
1 selected";
performSelector:@selector(myTaskMethod:)withObject:@"hehe"];
segLabel.text
=@"seg 2 selected";
& default:
segLabel.text
=@"seg default selected";
-(void)myTaskMethod:(NSString*)iden{
//& & NSAutoreleasePool *pool
=[[NSAutoreleasePool alloc]init];
& & @try {
& NSLog(@"11111");
self.array =
[[NSMutableArray alloc]
initWithObjects:[[NSString
initWithFormat:@"%@item1",iden],[[NSString
initWithFormat:@"%@item2",iden],nil];
[self.dataView
reloadData];
& & @catch
(NSException *exception) {
& & @finally
//& & [pool release];
最后在TableView相关的方法写入:
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section{
& & return [array count];
-(UITableViewCell*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath
*)indexPath{
& UITableViewCell* cell
=[tableView dequeueReusableCellWithIdentifier:@"tag"];
& & if (cell==nil) {
cell=[[[UITableViewCell alloc
]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"tag"] autorelease];
& & NSString * str = [array
objectAtIndex:indexPath.row];
cell.textLabel.text
& & return
2。在StoryBoard中拖入相应控件,并建立联系。
(或者,先拖入界面控件,后用右键在Assistant视图中自动生成代码)
3。右键UISegmentControl控件,将Value Changed事件与代码中的块进行关联。
关联TableView切换数据显示时,务必将StoryBoard中TableView的delegate,datasource与ViewController进行关联。
参见:http://blog.csdn.net/sjzsp/article/details/6320016
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。IOS开发之tableView点击行跳转并带有“显示”更多功能
作者:Livia.Chen
字体:[ ] 类型:转载 时间:
这篇文章给大家介绍通过点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多的功能,代码简单易懂,对ios点击tableview跳转相关知识感兴趣的朋友一起学习吧
首先给大家展示下效果图,觉得还满意的话,请继续学习代码实现过程。
一,工程图。
二,代码。
RootViewController.h
#import &UIKit/UIKit.h&
@interface RootViewController : UIViewController
&UITableViewDelegate,UITableViewDataSource&
UITableView * _tableV
NSMutableArray * provinceA
RootViewController.m
#import "RootViewController.h"
//详细页面
#import "DetailViewController.h"
@interface RootViewController ()
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view.
provinceArray = [[NSMutableArray alloc] initWithObjects:@"北京", @"上海", @"云南",@"四川",@"海南", @"江苏", @"香港", @"澳门", @"西藏", nil];
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 380) style:UITableViewStyleGrouped];
_tableView.delegate =
_tableView.dataSource =
[self.view addSubview:_tableView];
#pragma -mark -UITableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"] ;
cell.textLabel.text = [provinceArray objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureI
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60;
//点击进入下一页
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController* svc = [[DetailViewController alloc] init];
svc.title = [NSString stringWithFormat:@"%@",[provinceArray objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:svc animated:NO];
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
DetailViewController.h
#import &UIKit/UIKit.h&
@interface DetailViewController : UIViewController
&UITableViewDelegate,UITableViewDataSource&
UITableView* _tableV
NSArray* provinceA
NSArray* cityA
NSString* cityN
NSMutableArray* ditailN
NSString* ditialPlaceN
NSDictionary *dicForP
DetailViewController.m
#import "DetailViewController.h"
static int rowN
@interface DetailViewController ()
@implementation DetailViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view.
//传过来的城市名字
cityName = self.
//tableView显示行数
rowNumber = 20;
//tableView
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460 ) style:UITableViewStyleGrouped];
_tableView.delegate =
_tableView.dataSource =
[self.view addSubview:_tableView];
NSMutableArray* cityComparearr = [[NSMutableArray alloc] init];
ditailName = [[NSMutableArray alloc] init];
//城市的plist文件
dicForPlist = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cityName" ofType:@"plist"]];
//北京所有数据
provinceArr = [dicForPlist objectForKey:cityName];
for (int j = 0; j & [provinceArr count]; j++) {//遍历省的所有数据
cityArray = [provinceArr objectAtIndex:j];//取出每一个小数组
for (int i = 0; i & [cityArray count]; i++) {//遍历小数组
NSString* strstr = [cityArray objectAtIndex:i]; //得到小数组内容
if ([strstr isEqualToString:cityName] && j + 1 & [provinceArr count]) {
cityComparearr = [provinceArr objectAtIndex:j + 1];
if (![[cityArray objectAtIndex:i + 1] isEqualToString:[cityComparearr objectAtIndex:i + 1]]) {
[ditailName addObject:[cityArray objectAtIndex:i + 1]];
if ([strstr isEqualToString:cityName] && j + 1 == [provinceArr count]){
NSLog(@"last one?");
#pragma -mark -UITableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"];
if (indexPath.section == 0) {
cell.textLabel.text = [ditailName objectAtIndex:indexPath.row];
if (indexPath.section == 1) {
cell.textLabel.text = @"显示更多";
cell.textLabel.textAlignment = NSTextAlignmentC
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
if (rowNumber & [ditailName count]) {//显示到最多的时候
return [ditailName count];
return rowN
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1) {
rowNumber += 20;
[tableView reloadData];
NSLog(@"---跳转到另外一个页面----");
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
以上内容是小编给大家介绍的IOS开发之tableView点击行跳转并带有“显示”更多功能,有问题欢迎各位给我留言,我会及时和大家取得联系的,同时感谢大家一直以来对脚本之家网站的支持。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具}

我要回帖

更多关于 点击cell弹出view 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信