Gowhich

Durban's Blog

使用bootstrap这个方便的web UI框架,方便了自己,少些了很多的代码,至少兼容性方面,我觉的我就不用操心了,呵呵。

看看我自定义的table列表

css代码:

1
2
3
4
5
table.smoth{width:100%}
table.smoth thead tr.caption td.item{background-color: #E4E4E4;border:1px solid #ccc}
table.smoth tbody tr.list td{border:1px solid #ccc}
table.smoth tbody tr.list:nth-child(odd) td{background-color: #fff}
table.smoth tbody tr.list:nth-child(even) td{background-color: #F2F2F2}

html代码:

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
<div class="table">
<table class='smoth' >
<thead>
<tr class='caption'>
<td class='item'>电视剧名称</td>
<td class='item'>上线日期</td>
<td class='item'>ITV状态</td>
<td class='item'>导演</td>
<td class='item'>编剧</td>
<td class='item'>主演</td>
</tr>
</thead>
<tbody>
<?php for($i = 0; $i < 10; $i++):?>
<tr class='list'>
<td>咱俩的事</td>
<td>2013-01-13</td>
<td></td>
<td>David Zhang</td>
<td>David</td>
<td>Zhang</td>
</tr>
<?php endfor;?>
</tbody>
</table>
</div>

加入了一点php代码,实则是一个简单的循环

图片展示

先看一个例子:

1
.l-123f { color: red; }

  如果你第一次看到这个类名,你能在css文件立刻找到这个class吗?估计很难,因为这个类的名称只是某一个人能理解的符号再没有其他意义,所以这里没有一个准确的方法能够让你立即说出来。

让我们来看下这个类名定义:

1
.right-red { color:red; }

你可能很明确的知道这个class选择符的所起的作用。但是这里还有个问题,当你在一星期的时间需要重新设计。在重新设计的时候,这个模块被放置到了左边,而且还是绿色。这个类就不再有存在的价值。所以现在不得不选择,要么改变所有的属性值,要么放着它不动,这可能导致混乱。

最好不要在你的类名或者ID名中去加入颜色或者长宽的尺寸等带有属性的名字。你应该避免任何的属性值都是直接的词汇。(如box)直接属性可能会导致内容的分离。

让我们来看看最合理ID/CLASS的命名规范:

1
.product-description { color: red; }

  用这种样式定义的product-description(产品描述),不管你怎么改变,她都是那么的干净清晰。

总结为:最好不要在你的类名或者ID名中去加入颜色或者长宽的尺寸等带有属性的名字。

问题如题,原理很简单,只要在cell中给对应的button添加操作事件就好了。

示例代码如下:

navigationTableCell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// navigationTableCell.h
// xunYi7
//
// Created by david on 13-6-18.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface navigationTableCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UIButton *directorBtn;
@property (strong, nonatomic) IBOutlet UIButton *writerBtn;
@property (strong, nonatomic) IBOutlet UIButton *performerBtn;
@property (strong, nonatomic) IBOutlet UIButton *otherBtn;


@property (strong, nonatomic) IBOutlet UIButton *chancePerformerBtn;
@property (strong, nonatomic) IBOutlet UIButton *chanceOtherBtn;

@end
navigationTableCell.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
//
// navigationTableCell.m
// xunYi7
//
// Created by david on 13-6-18.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "navigationTableCell.h"

@implementation navigationTableCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}



@end

功能实现过程

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
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];

if(row == 0)
{
static NSString *navigationTableCellIdentifier = @"navigationTableCell";

UINib *navigationTableCellNib = [UINib nibWithNibName:@"navigationTableCell" bundle:nil];
[_dataTable registerNib:navigationTableCellNib forCellReuseIdentifier:navigationTableCellIdentifier];

navigationTableCell *cell = [self.dataTable dequeueReusableCellWithIdentifier:navigationTableCellIdentifier];
if(cell == nil)
{
cell = [[navigationTableCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:navigationTableCellIdentifier];
}


[cell.directorBtn addTarget:self
action:@selector(directorPush:)
forControlEvents:UIControlEventTouchUpInside];
[self giveButtonDrawCorner:cell.directorBtn];


[cell.writerBtn addTarget:self
action:@selector(writerPush:)
forControlEvents:UIControlEventTouchUpInside];
[self giveButtonDrawCorner:cell.writerBtn];

[cell.performerBtn addTarget:self
action:@selector(performerPush:)
forControlEvents:UIControlEventTouchUpInside];
[self giveButtonDrawCorner:cell.performerBtn];

[cell.otherBtn addTarget:self
action:@selector(otherPush:)
forControlEvents:UIControlEventTouchUpInside];
[self giveButtonDrawCorner:cell.otherBtn];

[cell.chancePerformerBtn addTarget:self
action:@selector(chancePerformerPush:)
forControlEvents:UIControlEventTouchUpInside];
[self giveButtonDrawCorner:cell.chancePerformerBtn];

[cell.chanceOtherBtn addTarget:self
action:@selector(chanceOtherPush:)
forControlEvents:UIControlEventTouchUpInside];
[self giveButtonDrawCorner:cell.chanceOtherBtn];

return cell;
}
static NSString *cellIdentifier = @"cellIdentifier";
UITableViewCell *cell = [self.dataTable dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

NSDictionary *dic = [self.dataDic objectForKey:[NSString stringWithFormat:@"%d",row]];

CGRect cellFrame = [cell frame];
cellFrame.size.height = 50.0;
[cell setFrame:cellFrame];
cell.textLabel.text = [dic valueForKey:@"title"];
cell.textLabel.font = [UIFont systemFontOfSize:18.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;

}

只要地址,中文也可以,英文也可以的

在使用之前要引入包CoreLocation

代码实例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
NSString *oreillyAddress = @"上海";  //测试使用中文也可以找到经纬度具体的可以多尝试看看~

CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];
[myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *placemarks, NSError *error) {
if ([placemarks count] > 0 && error == nil) {
NSLog(@"Found %lu placemark(s).", (unsigned long)[placemarks count]);
CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];
NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);
NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude);
}
else if ([placemarks count] == 0 && error == nil) {
NSLog(@"Found no placemarks.");
}
else if (error != nil) {
NSLog(@"An error occurred = %@", error); }
}];

参看文章:

http://blog.csdn.net/bihailantian1988/article/details/7618980

关于这个问题,我查找过了很多资料

最终的解决办法是:将UIAlertView在主线程上展现出来

实现过程如下:

1
2
3
4
5
6
7
8
9
+(void) showNetworkMessage
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络连接异常"
message:@"暂无法访问寻艺"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
}

然后在后面直接调用就可以了

Bizness Apps

Bizness Apps为中小企业提供了一个快速制作手机App的平台。它目前支持iOS(iPhone、 iPad)及Android平台上的本机App制作。用户完全不需要具备任何编程知识,只要进行按钮勾选及拖拽,就能完成大部分设计工作。建立App时, 首先选择你的App类型。Bizness Apps为每种类型提供了相应的模板,包含了该类型大部分的常见功能,用户只需要进一步在选单中选取你的App需要的功能即可完成本机App的设计。在 App完成后,Bizness Apps会帮你把App上传到他们在iOS和Android应用商店的帐号。

DevmyApp

一款傻瓜式的iOS应用程序开发软件。有了该应用,您就可以创建、设计和开发自己的iOS应用程序,同时还可避免为一些经常出现的功能模块重复编写代码。

Appsgeyser

使用AppsGeyser就可以让任何人都可以做应用程序的开发。 当然,这个程序并不能让你创建下一个愤怒的小鸟或者Foursquare。不过你仅仅想基于Web内容建立一个非常简单的应用程序的 话,AppsGeyser将会是你最佳的选择。AppsGeyser其实非常容易。

APPMakr

它的主要业务是为用户提供一个软件开发平台,让不会编程的用户也可以通过一个功能齐全的DIY工具包来开发手机应用程序。目前,AppMakr平台上的大部分应用主要是针对iOS系统,但针对Android及WP7的应用现在也正不断增长中。

Mobile Roadie

Mobile Roadie提供一个应用开发平台,整合YouTube, Brightcove, Flickr, Twitpic, Ustream, Topspin, 谷歌资讯,RSS, Twitter和Facebook。用户可使用该应用平台开发iOS应用和Android应用,并可以使用其提供的内容管理系统更新资讯,也可自行修改应 用细节。Mobile Roadie还提供了数据分析工具。
当然,APP开发工具不仅仅这些,例如:

专为艺术家打造的SwebApps

功能:SwebApps提供了一种在线服务,让你即便不知道如何编写代码也可以开发iPhone软件。 专为小公司打造,提供多种可供定制的模板,你还可以使用他们的图片库。

开发电子书应用利器 eBook App

功能: T用于通过电子书创建软件几乎支持所有格式的文件:PDF, Doc, Zip, CHM, HTML, TXT, FB2, PDB, PRC, Mobi, PDB, MHT, RTF此外用户还可以选择字体和大小,添加图片和注释,锁定横屏或竖屏等

游戏创意的实现者 GameSalad

功能: 这个下载工具可以让用户无需了解编程或脚本知识就可以开发游戏开发的软件可以发布到网页或iPhone上

每个都这么简单,但总结就是,好的东西绝对不会这么简单,当他简单的时候,他已经不在是好的

转自:http://mobile.51cto.com/hot-292923.htm

问题描述:

我在用UITableView的时候,滑动的时候,会出现卡的现象,原因是因为每次滑动的时候都会去远程加载图片,导致了这样的结果。

解决方案:

在网上找的时候找到了这样的一个类,名字叫做AsynImageView,下载地址为:http://vdisk.weibo.com/s/GcAN3

这个类文件就可以解决问题了

解决问题的过程:

自定义一个UITableViewCell,我的自定义代码如下:

attentionListCell.h

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
//
// attentionListCell.h
// xunYi6
//
// Created by david on 13-5-16.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AsynImageView.h"

@interface attentionListCell : UITableViewCell
@property (strong, nonatomic) IBOutlet AsynImageView *imageViewPic;
@property (strong, nonatomic) IBOutlet UILabel *name;
@property (strong, nonatomic) IBOutlet UILabel *index;
@property (strong, nonatomic) IBOutlet UILabel *rank;

@property (copy, nonatomic) UIImage *listImage;
@property (copy, nonatomic) NSString *listName;
@property (copy, nonatomic) NSString *listIndex;
@property (copy, nonatomic) NSString *listRank;
//--------------------------
//编辑操作
//--------------------------
@property (strong, nonatomic) UIImageView *checkImageView;
@property (nonatomic) BOOL checked;
- (void) setChecked:(BOOL)checked;

-(void) setSubViewsFrameEdit;
-(void) setSubViewsFrameNormal;

@end

attentionListCell.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//
// attentionListCell.m
// xunYi6
//
// Created by david on 13-5-16.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "attentionListCell.h"

@implementation attentionListCell

@synthesize listImage = _listImage;
@synthesize listName = _listName;
@synthesize listIndex = _listIndex;
@synthesize listRank = _listRank;

@synthesize checkImageView = _checkImageView;
@synthesize checked = _checked;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

-(void) setListImage:(UIImage *)value
{
if(![value isEqual:_listImage])
{
_listImage = [value copy];
self.imageViewPic.image = _listImage;
}
}

-(void) setListName:(NSString *)value
{
if(![value isEqualToString:_listName])
{
_listName = [value copy];
self.name.text = _listName;
}
}

-(void) setListIndex:(NSString *)value
{
if(![value isEqualToString:_listIndex])
{
_listIndex = [value copy];
self.index.text = _listIndex;
}

}

-(void) setListRank:(NSString *)value
{
if(![value isEqualToString:_listRank])
{
_listRank = [value copy];
self.rank.text = _listRank;
}
}

-(void) willTransitionToState:(UITableViewCellStateMask)state{
[UIView beginAnimations:@"ResetFrame" context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self cache:NO];


if(state == UITableViewCellStateDefaultMask)
{
[self setSubViewsFrameNormal];
}
else if(state == UITableViewCellStateShowingEditControlMask)
{
[self setSubViewsFrameEdit];
}
else if(state == UITableViewCellStateShowingDeleteConfirmationMask)
{
[self setSubViewsFrameEdit];
}

[UIView commitAnimations];
}

-(void) setSubViewsFrameEdit{
CGFloat offset = 10.0;

CGFloat imageX = 5.0 + offset;
CGFloat imageY = 5.0;
CGFloat imageWidth = 60.0;
CGFloat imageHeight = 60.0;

CGFloat nameX = 70.0 + offset;
CGFloat nameY = 5.0;
CGFloat nameWidth = 240.0 - offset;
CGFloat nameHeight = 15.0;

CGFloat indexX = 70.0 + offset;
CGFloat indexY = 25.0;
CGFloat indexWidth = 240.0 - offset;
CGFloat indexHeight = 15.0;

CGFloat rankX = 70.0 + offset;
CGFloat rankY = 45.0;
CGFloat rankWidth = 240.0 - offset;
CGFloat rankHeight = 15.0;

[self.imageViewPic setFrame:CGRectMake(imageX, imageY, imageWidth, imageHeight)];

[self.name setFrame:CGRectMake(nameX, nameY, nameWidth, nameHeight)];

[self.index setFrame:CGRectMake(indexX, indexY, indexWidth, indexHeight)];

[self.rank setFrame:CGRectMake(rankX, rankY, rankWidth, rankHeight)];
}


-(void) setSubViewsFrameNormal{
CGFloat offset = 0.0;

CGFloat imageX = 5.0 + offset;
CGFloat imageY = 5.0;
CGFloat imageWidth = 60.0;
CGFloat imageHeight = 60.0;

CGFloat nameX = 70.0 + offset;
CGFloat nameY = 30.0;
CGFloat nameWidth = 240.0 - offset;
CGFloat nameHeight = 15.0;

CGFloat indexX = 70.0 + offset;
CGFloat indexY = 25.0;
CGFloat indexWidth = 240.0 - offset;
CGFloat indexHeight = 15.0;

CGFloat rankX = 70.0 + offset;
CGFloat rankY = 45.0;
CGFloat rankWidth = 240.0 - offset;
CGFloat rankHeight = 15.0;

[self.imageViewPic setFrame:CGRectMake(imageX, imageY, imageWidth, imageHeight)];

[self.name setFrame:CGRectMake(nameX, nameY, nameWidth, nameHeight)];

[self.index setFrame:CGRectMake(indexX, indexY, indexWidth, indexHeight)];

[self.rank setFrame:CGRectMake(rankX, rankY, rankWidth, rankHeight)];
[self.checkImageView setFrame:CGRectMake(0.0, 0.0, 0.0, 0.0)];

}

//-------------------------------
// 重新定义editing的设置
//-------------------------------
-(void) setEditing:(BOOL)editing animated:(BOOL)animated{

if (self.editing == editing)
{
return;
}

[super setEditing:editing animated:animated];

if (editing)
{
CGFloat offset = 10.0;

CGFloat imageX = 5.0 + offset;
CGFloat imageY = 5.0;
CGFloat imageWidth = 60.0;
CGFloat imageHeight = 60.0;

CGFloat nameX = 70.0 + offset;
CGFloat nameY = 5.0;
CGFloat nameWidth = 240.0 - offset;
CGFloat nameHeight = 15.0;

CGFloat indexX = 70.0 + offset;
CGFloat indexY = 25.0;
CGFloat indexWidth = 240.0 - offset;
CGFloat indexHeight = 15.0;

CGFloat rankX = 70.0 + offset;
CGFloat rankY = 45.0;
CGFloat rankWidth = 240.0 - offset;
CGFloat rankHeight = 15.0;

[self.imageViewPic setFrame:CGRectMake(imageX, imageY, imageWidth, imageHeight)];

[self.name setFrame:CGRectMake(nameX, nameY, nameWidth, nameHeight)];

[self.index setFrame:CGRectMake(indexX, indexY, indexWidth, indexHeight)];

[self.rank setFrame:CGRectMake(rankX, rankY, rankWidth, rankHeight)];

if(_checkImageView == nil){
self.checkImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, self.index.frame.origin.y, 20.0, 20.0)];
NSString *unselectedPath = [[NSBundle mainBundle] pathForResource:@"attention_unselect" ofType:@"png"];
_checkImageView.image = [UIImage imageWithContentsOfFile:unselectedPath];
_checkImageView.backgroundColor = [UIColor whiteColor];
[self addSubview:_checkImageView];
}

[self setChecked:_checked];
}
else
{
_checked = NO;

// if(_checkImageView == nil){
// self.checkImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, self.index.frame.origin.y, 20.0, 20.0)];
// NSString *selectedPath = [[NSBundle mainBundle] pathForResource:@"attention_select" ofType:@"png"];
// _checkImageView.image = [UIImage imageWithContentsOfFile:selectedPath];
// _checkImageView.backgroundColor = [UIColor whiteColor];
// [self addSubview:_checkImageView];
// }
}

}


- (void) setChecked:(BOOL)checked
{
if (checked)
{
NSString *selectedPath = [[NSBundle mainBundle] pathForResource:@"attention_select" ofType:@"png"];
_checkImageView.image = [UIImage imageWithContentsOfFile:selectedPath];
self.backgroundView.backgroundColor = [UIColor whiteColor];
}
else
{
NSString *unselectedPath = [[NSBundle mainBundle] pathForResource:@"attention_unselect" ofType:@"png"];
_checkImageView.image = [UIImage imageWithContentsOfFile:unselectedPath];
self.backgroundView.backgroundColor = [UIColor whiteColor];
}
_checked = checked;
}

@end

实现的操作如下:

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
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *attentionListCellIdentifier = @"attentionListCell";

UINib *nib = [UINib nibWithNibName:@"attentionListCell" bundle:nil];
[self.dataTable registerNib:nib forCellReuseIdentifier:attentionListCellIdentifier];

attentionListCell *cell = [self.dataTable dequeueReusableCellWithIdentifier:attentionListCellIdentifier];

NSUInteger row = [indexPath row];

if(cell == nil)
{
cell = [[attentionListCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:attentionListCellIdentifier];
}

NSDictionary *dic = [self.dataDic objectForKey:[NSString stringWithFormat:@"%d",row]];

//艺人头像
cell.imageViewPic.imageURL = [NSString stringWithFormat:@"http://xxx.xxxxx.xxx/xxxxx/xxxxxx-%@-zfx.jpg",[dic valueForKey:@"person_id"]];

cell.name.text = [NSString stringWithFormat:@"%@",[dic valueForKey:@"title"]];

cell.index.text = [NSString stringWithFormat:@"Vlink指数: %.1f",[[NSString stringWithFormat:@"%@",[dic valueForKey:@"current_index"]] doubleValue]];

cell.index.textColor = [UIColor lightGrayColor];
cell.rank.text = [NSString stringWithFormat:@"排名:%@",[dic valueForKey:@"current_rank"]];
cell.rank.textColor = [UIColor lightGrayColor];

Item* item = [_items objectAtIndex:row];
[cell setChecked:item.isChecked];


cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

参考:http://blog.csdn.net/enuola/article/details/8639404

实现的过程是修改两个table 的controller类,修改方法如下:

1
2
3
4
5
6
7
8
9
10
#import <UIKit/UIKit.h>
@interface WelcomePavilionViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *array;
IBOutlet UITableView *tableView;
}
@property (nonatomic,retain) NSMutableArray *array;
@property (nonatomic,retain) UITableView *tableView;
@end

实现方法是:

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
#import “WelcomePavilionViewController.h”
#import “XmlWelcome.h”
@implementation WelcomePavilionViewController
@synthesize array,tableView;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
if ([self.array count]==0) {
[NSThread detachNewThreadSelector:@selector(myTaskMethod) toTarget:self withObject:nil];
}
}
-(void)myTaskMethod
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
XmlWelcome *parser=[[XmlWelcome alloc]
initWithContentsOfURL:[NSURL URLWithString:@"http://mp.myvsp.cn/welcomedemos/getpavilionxml.json?area=a&width=80&height=80&digest_length=20" ]];
//设置代理
[parser setDelegate:parser];
[parser parse];
self.array=parser.ones;
[self.tableView reloadData];
[parser release];
[pool release];

}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}

- (void)viewDidUnload {
self.array=nil;
self.tableView=nil;
}
- (void)dealloc {
[self.tableView release];
[self.array release];
[super dealloc];
}

- (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];
}
//表格设计
NSDictionary* one = [array objectAtIndex:indexPath.row];
cell.textLabel.text = [one objectForKey:@"title"];
cell.detailTextLabel.text = [one objectForKey:@"content"];
id path = [one objectForKey:@"image"];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data cache:NO];
cell.image=image;
[image release];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @”Hobby Information:”;
}
@end

这里总结一下,关键的总结点是这里

1
2
3
4
5
- (void)viewWillAppear:(BOOL)animated {
if ([self.array count]==0) {
[NSThread detachNewThreadSelector:@selector(myTaskMethod) toTarget:self withObject:nil];
}
}

然后再在自己的调用方法里面调用**[self.tableView reloadData];这个方法**

一般的问题是这样的

bool _WebTryThreadLock(bool), 0xxxxxx: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now…”

原因: update ui in background thread.

解决办法: update ui in main thread.

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do time-consuming task in background thread
// Return back to main thread to update UI
dispatch_sync(dispatch_get_main_queue(), ^{
_profile = [[UITextView alloc] init];
[_profile setFrame:CGRectMake(labelPersonProfileCaption.frame.origin.x, labelPersonProfileCaption.frame.origin.y + labelPersonProfileCaption.frame.size.height, width, height - 30.0)];

_profile.layer.borderColor = [[UIColor lightGrayColor] CGColor];
_profile.layer.borderWidth = 1.0;
_profile.layer.cornerRadius = 10.0;
_profile.delegate = self;
_profile.text = @"";
_profile.backgroundColor = [UIColor lightGrayColor];
_profile.editable = NO;
_profile.font = [UIFont systemFontOfSize:14.0];
_profile.backgroundColor = [UIColor whiteColor];

[_contentScroll addSubview:_profile];
});
});

参考资料:http://blog.csdn.net/chuwachen/article/details/8718253

电脑上的许多软件可以监控浏览器发出的HTTP请求, iPhone上有许多连网程序但没有自带软件可以实现监控, 为了方便测试这些请求是否正确而省去在程序中记录请求日志并逐一查找的麻烦, 可以利用Paros这个监控软件来实现.

以下是实现在Mac上监控iPhone发出的HTTP请求的具体步骤:

  1. 查看无线局域网IP:
1
davidzhang@davidzhang:~/Downloads/tools$ ifconfig
  1. 安装Paros

下载安装直接运行可执行文件即可,有两个文件,一个是.bat文件,一个是.sh文件,可以根据自己系统的环境不同运行不同的文件

下载地址1:http://sourceforge.net/projects/paros/

下载地址2:http://vdisk.weibo.com/s/G6wyY

  1. 设置Paros本地代理:

Paros->Tools->Options->Local proxy, Address填上”169.254.242.107″, 端口默认为8080

  1. 设置iPhone上网代理:

iPhone上: 设置->WiFi找到链接的网络->下拉找到HTTP代理->->手动->服务器填”169.254.242.107″, 端口填”8080″

  1. 查看HTTP请求:

iPhone打开访问任何连网程序, 可以在Paros的Sites下看到访问的网站, 右边可以选Reques/Response等信息.

0%