IOS实现选择城市后跳转Tabbar效果

2025-05-29 0 50

本文实例为大家分享了ios选择城市跳转tabbar的具体实现代码,供大家参考,具体内容如下

一、效果图

IOS实现选择城市后跳转Tabbar效果

IOS实现选择城市后跳转Tabbar效果

二、工程图

IOS实现选择城市后跳转Tabbar效果

三、代码

choosecityviewcontroller.h

?

1

2

3

4

5

6

7

8

9

10
#import <uikit/uikit.h>

@interface choosecityviewcontroller : uiviewcontroller

<uitableviewdelegate,uitableviewdatasource>

{

nsmutablearray * dataarray;

uitableview * mtableview;

}

@end

choosecityviewcontroller.m

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93
#import "choosecityviewcontroller.h"

#import "detailviewcontroller.h"

@interface choosecityviewcontroller ()

@end

@implementation choosecityviewcontroller

- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil

{

self = [super initwithnibname:nibnameornil bundle:nibbundleornil];

if (self) {

// custom initialization

}

return self;

}

- (void)viewdidload

{

[super viewdidload];

// do any additional setup after loading the view.

//读取plist文件

[self readplistfile];

//初始化tableview

[self inittableview];

}

#pragma -mark -functions

-(void)readplistfile

{

dataarray = [[nsmutablearray alloc] initwithcapacity:0];

nsstring * path = [[nsbundle mainbundle] pathforresource:@"city" oftype:@"plist"];

nsdictionary * dict = [[nsdictionary alloc] initwithcontentsoffile:path];

nsenumerator * enumerator = [dict keyenumerator];

nsstring * key;

while (key = [enumerator nextobject]) {

nsdictionary * t = [dict objectforkey:key];

[dataarray addobject:t];

}

nslog(@"%@",dataarray);

}

-(void)inittableview

{

mtableview = [[uitableview alloc] initwithframe:self.view.bounds style:uitableviewstyleplain];

mtableview.delegate = self;

mtableview.datasource = self;

mtableview.autoresizingmask = uiviewautoresizingflexibleheight;

[self.view addsubview:mtableview];

}

#pragma -uitableviewdelegate

-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section

{

return [dataarray count];

}

-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

{

static nsstring * id = @"cellid";

uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier:id];

if (cell == nil)

{

cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:id];

}

nsdictionary *dict = [dataarray objectatindex:indexpath.row];

cell.textlabel.text = [dict objectforkey:@"city_name"];

return cell;

}

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath

{

nsdictionary * dict = [dataarray objectatindex:indexpath.row];

//把所选择的城市保存到本地

[[nsuserdefaults standarduserdefaults] setobject:[dict objectforkey:@"city_id"] forkey:@"city_id"];

[[nsuserdefaults standarduserdefaults] setobject:[dict objectforkey:@"city_name"] forkey:@"city_name"];

//跳转到另一个有tabbar的页面

detailviewcontroller *detail=[[detailviewcontroller alloc]init];

[self.navigationcontroller pushviewcontroller:detail animated:no];

}

- (void)didreceivememorywarning

{

[super didreceivememorywarning];

// dispose of any resources that can be recreated.

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 IOS实现选择城市后跳转Tabbar效果 https://www.kuaiidc.com/92922.html

相关文章

发表评论
暂无评论