IanMK2 Blog

선언은

NSCalendar *calendar = [NSCalendar currentCalendar];

unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;

NSDateComponents *c = [calendar components:unitFlags fromDate:[NSDate date]]; 

 

나중에 release하는 것을 잊지말자


[c year]    

[c month] 

[c day]    

[c hour]   

[c minute]

[c second]

Posted by IanMK2
앱을 만들던도중 특정영역의 터치를 검사해서 이벤트를 발생시킬 일이 생겼다.
이리저리 찾아본결과
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

CGPoint currentPos = [[touches anyObject] locationInView:self];

if(CGRectContainsPoint(CGRectMake(10,10,100, 100 ),currentPos))
작업실행;
}

위와같이 뷰클래스 소스에 추가해주면된다.
위 메서드 말고도뒤가 ended등으로 끝나는 시리즈가 있다.

*주의사항 : 스크롤뷰는 위의 함수가 호출이 안된다. 그래서 스크롤뷰안에 다시 뷰를 생성하고 그 뷰안에서 저 함수를 추가하고 처리해야한다.
Posted by IanMK2
UIPickerView는 윈도우로 치자면 콤보박스와 비슷하다. 하지만 좀 더 화려하고 굴리는 맛(?)이 있다.

써먹는 방법은 여러가지가 있지만 
1. 인터페이스빌더에서 아얘 박아넣는법. 
2. 동적으로 생성해서 불러내는법.
등이 쓰인다.(액션시트에 넣는방법도 있다)

기본적으로 테이블뷰와 아주 유사하다. 델리게이트를 추가하는것을 잊지말자.

다음은 사용되는 오버라이딩함수이다.

데이터소스가져오는것
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return (NSString*)[pointAry objectAtIndex:row];
}

컴포넌트의 개수 - 데이트피커를 떠올려보라. 시간,분,초등이 있지않는가? 바로 그 항목의 수이다.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}

데이터의 개수
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [pointAry count] ;
}

피커뷰의 가로사이즈를 설정하는것
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    return 100;
}

피커의 값이 변경되면 호출되는 함수
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog(@"%d",row);
}

위 함수 등이 사용된다.
인터페이스에서 박아넣는법을 사용한다면 위함수만 추가 해주면 될것이다.
본인은 동적으로 불러냈다가 다시 집어넣어야하기 때문에 두번째 방법으로 하였다.

UIPickerview를 생성하고 불러낼때에는 

UIPicker pickerview = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 480, 320, 0)];  
//일부러 뷰밖에서 생성한다.
pickerview.delegate = self;
pickerview.showsSelectionIndicator = YES;
[self.view addSubview:pickerview];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
pickerview.transform = CGAffineTransformMakeTranslation(0, -275); //위로 쭈욱하고 올라온다.
[UIView commitAnimations];
[self pickerView:pickerview didSelectRow:4 inComponent:0];//자동으로 처음값을 설정


집어넣을땐
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
pickerview.transform = CGAffineTransformMakeTranslation(0, 275); //그냥 아래로 다시 내려주자
[UIView commitAnimations];



물론 다 사용하고 난뒤에는 뷰에서 빼주고 릴리즈해주자.


Posted by IanMK2
strAddr = [strAddr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];


익스플로러에서는 되는데 크롬이나 사파리는 안되서 짜증짜증
인코딩이 문제였다
Posted by IanMK2
UIAlertView와 비슷하다

- (IBAction)captureClicked:(id)sender{
UIActionSheet *ask = [[UIActionSheet alloc] initWithTitle:@"사진" delegate:self cancelButtonTitle:@"취소" destructiveButtonTitle:@"앨범에서 선택" otherButtonTitles:@"찍기",nil];
//other버튼에서 마지막에 nil로 하는거 잊지말자 가끔씩 깜빡하는데 콘솔봐도 에러메세지 안뜨고 삽질하기 쉽다.

ask.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[ask showInView:self.view];
[ask release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch(buttonIndex)
{
case 0:
[self getPhotos];
break;
case 1:
break;

}
}


삽질하지말고 액션시트 델리게이트정도는 추가하자
Posted by IanMK2