아이폰어플개발정보2010. 10. 12. 04:54
테이블뷰에서 셀하나가 터치되었을때 체크표시하기 -Accessory in apple source

리스트뷰에서 체크되었을때



#import "MyTableViewController.h"


@interface MyTableViewController ()

@property (nonatomic, retain) NSMutableArray *dataArray;

@end


@implementation MyTableViewController


@synthesize dataArray;


- (void)viewDidLoad

{

// load our data from a plist file inside our app bundle

NSString *path = [[NSBundlemainBundle] pathForResource:@"tableData"ofType:@"plist"];

self.dataArray = [NSMutableArrayarrayWithContentsOfFile:path];

}



// called after the view controller's view is released and set to nil.

// For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc.

// So release any properties that are loaded in viewDidLoad or can be recreated lazily.

//

- (void)viewDidUnload

{

self.dataArray = nil;

}



- (void)dealloc

{

    [dataArrayrelease];

[superdealloc];

}



#pragma mark - UITableView delegate methods


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

{

return [dataArraycount];

}



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

{

[selftableView: self.tableViewaccessoryButtonTappedForRowWithIndexPath: indexPath];

[self.tableViewdeselectRowAtIndexPath:indexPath animated:YES];

}



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

{

static NSString *kCustomCellID = @"MyCellID";

UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:kCustomCellID];

if (cell == nil)

{

cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:kCustomCellID] autorelease];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

cell.selectionStyle = UITableViewCellSelectionStyleBlue;

}

NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row];

cell.textLabel.text = [item objectForKey:@"text"];


[item setObject:cell forKey:@"cell"];

BOOL checked = [[item objectForKey:@"checked"] boolValue];

UIImage *image = (checked) ? [UIImage imageNamed:@"checked.png"] : [UIImage imageNamed:@"unchecked.png"];

UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);

button.frame = frame;// match the button's size with the image size

[button setBackgroundImage:image forState:UIControlStateNormal];

// set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet

[button addTarget:selfaction:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];

button.backgroundColor = [UIColorclearColor];

cell.accessoryView = button;

return cell;

}



- (void)checkButtonTapped:(id)sender event:(id)event

{

NSSet *touches = [event allTouches];

UITouch *touch = [touches anyObject];

CGPoint currentTouchPosition = [touch locationInView:self.tableView];

NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];

if (indexPath != nil)

{

[selftableView: self.tableViewaccessoryButtonTappedForRowWithIndexPath: indexPath];

}

}



- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row];

BOOL checked = [[item objectForKey:@"checked"] boolValue];

[item setObject:[NSNumbernumberWithBool:!checked] forKey:@"checked"];


UITableViewCell *cell = [item objectForKey:@"cell"];

UIButton *button = (UIButton *)cell.accessoryView;

UIImage *newImage = (checked) ? [UIImage imageNamed:@"unchecked.png"] : [UIImage imageNamed:@"checked.png"];

[button setBackgroundImage:newImage forState:UIControlStateNormal];

}


@end


#import <UIKit/UIKit.h>


@interface MyTableViewController : UITableViewController

{

@private

NSMutableArray *dataArray;

}


@end


Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 8. 24. 09:32

 
공부를 하다 보면 책에 나오는 간단 간단한 소스가 아닌 전체 프로그램에 대한 소스를 보고 싶어질 때가 있습니다.
그래서 자료를 찾아 보았습니다. 참고하세요.

<트위터 클라이언트>
http://github.com/blog/329-natsuliphone-iphone-twitter-client
http://code.google.com/p/tweetero/
http://github.com/facebook/three20
http://code.google.com/p/iphoneebooks/
http://iphone.wordpress.org/
http://www.funambol.com/solutions/iphone.php
http://code.google.com/p/cocos2d-iphone/
http://code.google.com/p/mintgostop/  (고스톱)
http://www.joystiq.com/2009/03/24/carmack-releases-open-source-wolfenstein-for-iphone/
http://kldp.net/projects/taekbae/src
http://www.iphonear.org/
http://apparentlogic.com/openflow/
http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/
http://open.iphonedev.com/
http://joehewitt.com/post/the-three20-project/
 


출처 : http://blog.naver.com/PostView.nhn?blogId=baek2187&logNo=150079874332
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 8. 23. 09:36
[펌] iPhone용 Open Source 모음
공부를 하다 보면 책에 나오는 간단 간단한 소스가 아닌 전체 프로그램에 대한 소스를 보고 싶어질 때가 있습니다.
그래서 자료를 찾아 보았습니다. 참고하세요.
 
<여러 UI 모음: photo viewer, etc>
http://github.com/facebook/three20 (초기에는 facebook 어플이었으나 현재는 여러 UI 모음으로 바뀜 )
http://code.google.com/p/route-me/

<E-mail>
 
 
<달력>
http://ved-dimensions.blogspot.com/2009/04/iphone-development-creating-native_09.html

<sqlite>

<계산기>

<트위터 클라이언트>
http://github.com/blog/329-natsuliphone-iphone-twitter-client
http://github.com/facebook/facebook-iphone-sdk

http://www.joystiq.com/2009/03/24/carmack-releases-open-source-wolfenstein-for-iphone/

http://code.google.com/p/google-toolbox-for-mac/


http://kldp.net/projects/taekbae/src

http://code.google.com/p/simple-iphone-image-processing/


http://www.chaosinmotion.com/flowcover.m (매가박스 어플에서 참고함)


출처 : http://blog.naver.com/PostView.nhn?blogId=baek2187&logNo=150086976224
Posted by 오늘마감

댓글을 달아 주세요