@property에서 nonatomic과 retain ??
2011-03-01 15:30:26

@property (nonatomic, retain) ~ 이렇게 사용하는 이유가 무엇일까?

기본속성 (선언을 하지 않을 경우)은 atomic으로 선언되는데 프로퍼티를 접근할때 lock과 unlock를 반복하여

접근한다는 의미로써, 즉, 프로퍼티를 보호한다는 의미입니다.

보통은 nonatmoic 으로 선언하는데 "메모리를 절약" 하기 위해 사용합니다.

(lock과 unlock을 하지 않기 때문에...)

하지만! 동시에 여러 쓰레드를 사용하는 경우 (멀티 쓰레드)에는 하나의 프로퍼티로 접근하게 되면 문제가 생김

그래서 이때에는 atomic으로 사용하는 것이 좋습니다.

모든 objective-c에서는 메모리 관리를 레퍼런스 카운트를 이용하는데,,

그래서 모든 객체는 자신을 참조하는 수에 대한 내부 카운트를 가지고 있습니다.

보통 retain을 사용하는데 대충 "참조를 하나 더 추가" 한다는 뜻입니다.

- retain : 해당 객체의 레퍼런스 카운트를 1올림

- alloc : 해당 객체에 메모리를 할당하고 레퍼런스 카운트를 1 올림

- copy : 해당 객체의 복사본을 만듦. 그리고 그 복사본의 레퍼런스 카운트를 1 올림

- release : 해당 객체의 레퍼런스 카운트를 1 낮춤

- autorelease : 정해지지 않은 시점에 해당 객체의 레퍼런스 카운트를 1 낮춤

[출처] @property에서 nonatomic과 retain ??|작성자 윈플

▼ more
viewWillAppear가 실행되지 않는다면~!
2011-03-01 14:45:52

[self.navigationController pushViewController:childViewController animated:[BOOL]];

[childViewController viewWillAppear:YES];

▼ more
iPhone Table.h
2011-03-01 12:51:48

//

// TweetViewController.h

// TwitterBiKE

//

// Created by Kyungmin Lee on 1/30/11.

// Copyright 2011 __MyCompanyName__. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface TweetViewController : UITableViewController <UITableViewDelegate,UITableViewDataSource>{

NSArray *listData;

}

@property (nonatomic, retain) NSArray *listData;

@end

▼ more
Iphone Table.m
2011-03-01 12:50:33

//

// TweetViewController.m

// TwitterBiKE

//

// Created by Kyungmin Lee on 1/30/11.

// Copyright 2011 BiKE. All rights reserved.

//

//메모리 해제는 '- (void)viewDidUnload'와 '- (void)dealloc' 에서 모두 신경써야 한다.

#import "TweetViewController.h"

#define kScreenNameValueTag 1

#define kCreatingAtValueTag 2

#define kTweetTextValueTag 3

@implementation TweetViewController

@synthesize listData;

#pragma mark -

#pragma mark View lifecycle

- (void)viewDidLoad {

NSString * str1 = @"asdf";

NSString * str2 = @"fdsasl;dfijhasldfijafasdfasfsadfasdfasfsadf";

NSArray *array = [[NSArray alloc] initWithObjects:str1,str2,str2,str2,str2,nil];

self.listData = array;

[str1 release];

[str2 release];

[array release];

}

#pragma mark -

#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

// Return the number of sections.

return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

// Return the number of rows in the section.

return [self.listData count];

}

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//셀의 식별자를 설정한다.이유는 잘 모름 아직은;

static NSString *tweetTableIdentifier =@"TweetTableIdentifier";

//셀 객체를 얻어온다.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tweetTableIdentifier];

//셀의 모양(appearance)을 결정하는 부분.

if(cell ==nil){//셀이 비었다면 새로운 셀을 만든다.

cell = [[[UITableViewCell alloc]

initWithStyle:UITableViewCellStyleDefault

reuseIdentifier:tweetTableIdentifier] autorelease];

//UILabel을 이용하여 글 상자를 만든다.

// ScreenName LabelRect

CGRect screenNameValueRect = CGRectMake(0,0,70,8);

UILabel *screenNameValue = [[UILabel alloc] initWithFrame:screenNameValueRect];

screenNameValue.font = [UIFont systemFontOfSize:8];

screenNameValue.tag = kScreenNameValueTag;

[cell.contentView addSubview: screenNameValue];

[screenNameValue release];

}

NSUInteger row = [indexPath row];

//NSLog(@"Now %d",row);

//row 에 따라서 다른 그림이 보이도록한다.

UIImage *image = [UIImage imageNamed:@"tweetTAB.png"];

cell.imageView.image = image;

// UILabel을 이용하여 글 상자에 글을 넣는다.

//Screen Name

NSString *rowData = [self.listData objectAtIndex:row];

UILabel *screenName = (UILabel *)[cell.contentView viewWithTag:kScreenNameValueTag];

screenName.text = rowData;

return cell;

}

#pragma mark -

#pragma mark Table view delegates

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Navigation logic may go here. Create and push another view controller.

/*

<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];

// ...

// Pass the selected object to the new view controller.

[self.navigationController pushViewController:detailViewController animated:YES];

[detailViewController release];

*/

}

#pragma mark -

#pragma mark Memory management

- (void)didReceiveMemoryWarning {

// Releases the view if it doesn't have a superview.

[super didReceiveMemoryWarning];

// Relinquish ownership any cached data, images, etc. that aren't in use.

}

- (void)viewDidUnload {

//\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.

// For example: self.myOutlet = nil;

self.listData = nil;

[super viewDidUnload];

}

- (void)dealloc {

[listData release];

[super dealloc];

}

@end

▼ more