Gowhich

Durban's Blog

方法 1:

如果,UITableView的类型为UITableViewStyleGrounped,发现使用_tableView.backgroundColor = [UIColor clearColor]后,tableView的背景色仍然是默认的色,上网查了下:
_tableView.backgroundView = nil;可以搞定。
测试下发现确实可以,但是不知道以前的版本不确定有没有backgroundView的,所以最好加个判断吧:

1
2
3
4
if (mainTableView.backgroundView)
{
mainTableView.backgroundView =nil;
}

如果类型为UITableViewStylePlain,[UIColor clearColor]仍然有效,怪哉!
正常情况下grouped样式(UITableViewStyleGrouped)UITableViewCell都是有边框的,如果要去掉边框可以用:

1
2
3
UIView *tempView = [[[UIView alloc] init] autorelease];
[cell setBackgroundView:tempView];
[cell setBackgroundColor:[UIColor clearColor]];

其实很简单,把backgroundView设置为一个空的View,然后就干净了。看了下UITableViewCell的文档,backgroundView在plain-style的TableView里面是nil,在grouped-style的TableView里面并不是空的,所以这里设置空就ok了,这是目前为止我见到的最完美的解决方案。

方法 2:

1
[tableView setSeparatorColor:[UIColor clearColor]];

方法 3:

1
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

看到一篇帖子,感觉写的很牛,摘抄在这里了:(代码如下)

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
(function () {
if (Error.captureStackTrace && Object.defineProperty) {

var global = window;

Object.defineProperty(global, '__STACK__', {
get: function () {
var old = Error.prepareStackTrace;
Error.prepareStackTrace = function (error, stack) {
return stack;
};

var err = new Error();
Error.captureStackTrace(err, arguments.callee);
Error.prepareStackTrace = old;

return err.stack;
}
});

Object.defineProperty(global, '__LINE__', {
get: function () {
return __STACK__[1].getLineNumber();
}
});

Object.defineProperty(global, '__FILE__', {
get: function () {
return __STACK__[1].getFileName();
}
});
}
})();

var test = function () {
console.log(__LINE__,__FILE__);
};

test();

自己的应用中需要一种非普通格式的cell,于是自己就定义了一下;基本上的代码类似如下:

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
static NSString *captionCellWithIdentifier = @"captionCell";

//使用自定义的cell模板
static BOOL nibRegistered = NO;
if(!nibRegistered){
UINib *nib = [UINib nibWithNibName:@"captionCell" bundle:nil];
[self.personTable registerNib:nib forCellReuseIdentifier:captionCellWithIdentifier];
nibRegistered = YES;
}


captionCell *cell = [self.personTable dequeueReusableCellWithIdentifier:captionCellWithIdentifier];
if(cell == nil){
cell = [[captionCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:captionCellWithIdentifier];
}


cell.contentView.backgroundColor = [UIColor grayColor];

cell.firstTitle.text = @"3月4日 艺人新媒体指数";
cell.firstTitle.textColor = [UIColor whiteColor];
cell.secondTitle.text = @"www.vlinkage.com";
cell.secondTitle.textColor = [UIColor whiteColor];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
return cell;

因为按钮的要求,好友导航的限制,想着自己自定义一个barbuttonitem,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.leftBtn setFrame:CGRectMake(10.0, 5.0, 70.0, 30.0)];
[self.leftBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[self.leftBtn setTitle:@"返回" forState:UIControlStateNormal];
[self.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.leftBtn setTintColor:[UIColor redColor]];
// [self.leftBtn setImage:[UIImage imageNamed:@"back_60_30"] forState:UIControlStateNormal];

self.leftBtn.layer.cornerRadius = 10.0;
self.leftBtn.layer.borderWidth = 1.0;

[self.leftBtn addTarget:self
action:@selector(returnToPrev)
forControlEvents:UIControlEventTouchUpInside];
[self.leftBtn setTag:1];
[self.navigationBar addSubview:self.leftBtn];

最近写app,在一个部分想自定义一下NavigationBar:

1
2
3
4
5
6
7
8
9
self.navigationBar = [[UINavigationBar alloc]
initWithFrame:CGRectMake(0.0, 0.0, width, 40.0)];
[self.navigationBar setBackgroundColor:[UIColor redColor]];

self.navigationBar.tintColor = [UIColor redColor];
[self.view addSubview:self.navigationBar];

UINavigationItem *navigationTitle = [[UINavigationItem alloc] initWithTitle:@"艺人指数排行榜"];
[self.navigationBar pushNavigationItem:navigationTitle animated:NO];

别忘记一个操作就是隐藏掉默认的navigationBar:

代码如下:

1
[self.navigationController setNavigationBarHidden:YES];

这行代码可以加到didFinishLaunchingWithOptions中,也可以加到viewDidLoad

为了使用版本号的问题,我搜了点资料,做点记录

1
2
3
4
5
6
7
8
9
10
11
NSLog([[UIDevice currentDevice] name]); // Name of the phone as named by user
NSLog([[UIDevice currentDevice] uniqueIdentifier]); // A GUID like string
NSLog([[UIDevice currentDevice] systemName]); // "iPhone OS"
NSLog([[UIDevice currentDevice] systemVersion]); // "2.2.1"
NSLog([[UIDevice currentDevice] model]); // "iPhone" on both devices
NSLog([[UIDevice currentDevice] localizedModel]); // "iPhone" on both devices
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 4.0)
{
// iPhone 4.0 code here
}

我在做我的iOS应用中,遇到了这样的情况:错误代码如下:

1
2
3
2013-05-13 21:46:47.985 xunYi4[31694:c07] nested pop animation can result in corrupted navigation bar
2013-05-13 21:46:48.336 xunYi4[31694:c07] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2013-05-13 21:46:48.337 xunYi4[31694:c07] Unbalanced calls to begin/end appearance transitions for <personViewController: 0x75a01b0>.

使得我的运行的结果是,在调用pushViewConroller的时候出现了两次push,导致程序不能达到自己想要的效果,于是查找资料,最终我的解决方案是:如下:

1
2
3
4
personViewController *person = [[personViewController alloc] initWithNibName:@"personViewController" bundle:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
person.navigationItem.title = button.titleLabel.text;
[self.navigationController pushViewController:person animated:YES];

达到了我要的效果,但是问题是这个报错的信息还是存在,请求高手给予指点

  • 第一步
    这里需要注意,要选择真机,否则Archive 会是灰色的。
    点击后,系统会自动编译一次:

  • 第二步:
    在你刚刚生成的程序上点击右键,并且点击Show in Finder。

  • 第三步:
    在打开的窗口中选择 生成的文件 右键点击,显示包内容。

  • 第四步:
    你会看到一个上面有圆圈禁止符号的图标,这是一个重要的文件,不要关闭窗口,我们一会儿的操作需要用到它。

  • 第五步:
    打开iTunes 把上面一步的文件 拖拽至 iTunes 中。

  • 第六步:
    右键点击iTunes中生成的文件,点击Show in Finder。

  • 第七步,也是最后一步。
    现在显示的这个ipa 文件就是可以给其他机器安装的了。 如果,你安装的机器,没有在你程序的测试证书中,是不能够安装的。除非你的机器是越狱机,越狱机可以安装。

新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一级页面的title较长,在进入第二级页面后返回按钮leftButtonItem的title就会变得很长,对NavigationBar空间占用很大,而且不美观,于是使用代码对leftButtonItem的title文本进行修改,无论是设置self.navigationItem.leftBarButtonItem.title = @"返回";还是self.navigationItem.backBarButtonItem.title = @"返回";都没有效果,title文本始终不会发生变化。到网上乱搜一通后,得到了以下解决方法,相对来说比较简单,特记录如下:

在第一级页面的viewDidLoad方法中加入以下代码:

1
2
3
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] init];
backButtonItem.title = @"返回";
self.navigationItem.backBarButtonItem = backButtonItem;

也就是用一个新的按钮在进行导航前将原来的返回按钮替换掉就可以了。
可以如下设置 但是这样的缺点是那个按键会变成方形 可以添加图片来进行修改。

1
2
3
4
5
6
7
8
9
10
11
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(backToPrevious)];

self.navigationItem.leftBarButtonItem = backButton;

- (void)backToPrevious
{
[self.navigationController popViewControllerAnimated:YES];
}

添加图片的相关代码如下

1
2
3
4
5
6
7
8
UIButton *leftButton = [[UIButtonalloc] initWithFrame:CGRectMake(0, 0, 60, 40)];
[leftButton setTitle:@"返回"forState:UIControlStateNormal];
[leftButton setImage:[UIImageimageNamed:@"UINavigationBar.png"] forState:UIControlStateNormal];
[leftButton setImage:[UIImageimageNamed:@"UINavigationBar.png"] forState:UIControlStateHighlighted];
[leftButton addTarget:selfaction:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItemalloc] initWithCustomView:leftButton];
[leftButton release];
self.navigationItem.leftBarButtonItem = leftItem;

网站上搜集了一些,关于iphone的尺寸方面的资料:简单的贴到下面,喜欢的朋友可以自己查看一下:

Element Size (in points)
Window (including status bar) 320 x 480 pts
Status Bar (How to hide the status bar) 20 pts
View inside window (visible status bar) 320 x 460
Navigation Bar 44 pts
Nav Bar Image/Toolbar Image up to 20 x 20 pts (transparent PNG)
Tab Bar 49 pts
Tab Bar Icon up to 30 x 30 pts (transparent PNGs)
Text Field 31 pts
Height of a view inside a navigation bar 416 pts
Height of a view inside a tab bar 411 pts
Height of a view inside a navbar and a tab bar 367 pts
Portrait Keyboard height 216 pts
Landscape Keyboard height 140 pts

Points vs. Pixels
The iPhone 4 introduced a high resolution display with twice the pixels of previous iPhones. However you don’t have to modify your code to support high-res displays; the coordinate system goes by points rather than pixels, and the dimensions in points of the screen and all UI elements remain the same.
iOS 4 supports high resolution displays (like the iPhone 4 display) via the scale property on UIScreen, UIView, UIImage, and CALayer classes. If the object is displaying high-res content, its scale property is set to 2.0. Otherwise it defaults to 1.0.
All you need to do to support high-res displays is to provide @2x versions of the images in your project. See the checklist for updating to iOS4 or Apple documentation for Supporting High Resolution Screens for more info.
Adjusting Sizes
Click here to see how to adjust View Frames and Bounds.
Additional References

  • Apple Documentation: Points vs. Pixels
  • Apple Documentation: UIBarButtonItem Class Reference says “Typically, the size of a toolbar and navigation bar image is 20 x 20 points.”
  • Apple Documentation: UITabBarItem Class Reference says “The size of an tab bar image is typically 30 x 30 points.”
0%