我跟着釋放自定義類對象
@interface Res : NSObject {
int _id;
NSString *_name;
NSString *_comments;
// ... and to many other objects.
}@property (nonatomic) int id;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *comments;
在我看來,一個名爲RES I類有一個UITableView,我希望用戶在的UITextField內UITableViewCell的,所以我已經添加下面的代碼輸入值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//code for creating cell
switch (indexPath.row) {
case 0:
// Label
[[cell textLabel] setText:@"Name :"];
// Textbox
UITextField *_txtName = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, 180, 44)];
[_txtName setDelegate:self];
[_txtName setTag:0];
[cell.contentView addSubview:_txtName];
[_txtName release], _txtName = nil;
break;
case 1:
// ......
}
現在,當用戶在文本框中輸入值,我通過以下方法
- (void)textFieldDidEndEditing:(UITextField *)textField
{
switch ([textField tag]) {
case 0:
[_resTemp setName:[textField text]];
break;
default:
break;
}
}
我宣佈得到它_resTemp
變量作爲我的.h文件實例變量
上ViewDidLoad
方法我寫_resTemp = [[Res alloc] init];
和ViewDidUnload
方法我釋放它像[_resTemp release];
,我也釋放它的dealloc方法相同。
我仍然得到關於這個變量的內存泄漏。
我不明白在哪裏發佈這個對象,或者我需要改變我的邏輯。 任何人都可以給我一些指向UITableView數據輸入代碼的鏈接嗎?
查看發佈前的預覽..你的代碼格式不正確 – Krishnabhadra 2011-03-28 08:22:34