我有一个自定义UITableViewCell,其中包含几个UIButtons.每个按钮的框架位置相对于单元格宽度.我设置了autoresizingMask = UIViewAutoresizingFlexibleWidth,因此当应用程序以横向或纵向模式启动时,它将正确调整单元格宽度和按钮位置.
问题是当设备从一种模式旋转到另一种模式时,按钮不会调整位置,因为UITableViewCell是可重复使用的.换句话说,基于新的UITalbeView宽度不会初始化单元格,因为在设备旋转之前调用单元格的函数initWithStyle,而在设备旋转之后不再调用该单元格.有什么建议?
我试图使用initWithStyle自定义TableViewCell,因为它表示在3.0之后不推荐使用initWithFrame.以前使用initWithFrame一切正常.
有没有可用的教程或示例代码?谢谢.
背景 - 在我的iPhone应用程序中,我有一个自定义的UITableViewController - 我将通过将现有的"(id)initWithStyle:(UITableViewStyle)样式"方法扩展到扩展的自定义方法来传递一些必需的配置.
问题 - 确保此自定义控制器类的用户只能调用我的自定义init方法而不是initWithStyle或任何其他init方法的最佳方法是什么?
为什么我会收到这些错误? alt text http://img39.imageshack.us/img39/2203/help.tif
它说:
错误:请求成员"jokeTableView",而不是struction或union
那是什么意思?为什么它会破裂.我尝试阅读有关initWithStyle但我只能赶上它
这是我的.h文件:
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController {
NSMutableArray *jokes;
IBOutlet UITableView *jokeTableView;
}
@property (nonatomic, retain) NSMutableArray *jokes;
@end
Run Code Online (Sandbox Code Playgroud)
谢谢!
我升级到XCODE 4.2,突然我得到了所有这些警告信号.大多数我能够修复,但以下我不知道如何.我试图阅读它但仍然有问题.
不推荐使用的代码是:
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
Run Code Online (Sandbox Code Playgroud)
我知道我需要使用以下内容:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
Run Code Online (Sandbox Code Playgroud)
但是,当我测试时,我遇到了CellFrame等问题.
有人可以给我一个提示,我应该如何用initWithStyle替换已弃用的代码并得到相同的结果?
这是完整的代码:
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
CGRect CellFrame = CGRectMake(0, 0, 300, 60);
CGRect Label1Frame = CGRectMake(10, 10, 290, 25);
CGRect Label2Frame = CGRectMake(30, 33, 270, 25);
CGRect Label3Frame = CGRectMake(30, 56, 270, 25);
UILabel *lblTemp;
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.3f alpha:1.0f]; …
Run Code Online (Sandbox Code Playgroud) iphone ×3
objective-c ×3
uitableview ×2
cocoa ×1
deprecated ×1
init ×1
ios ×1
reusability ×1
rotation ×1
xcode4.2 ×1