본문 바로가기
300x250

분류 전체보기241

NSDictionary // 방법 1 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil]; // 방법 2 NSDictionary *dictionary = @{@"key", @"value"}; dictionary 배열에서 원하는 key의 value 개수 필터링 list : [ { "age" : 3, "grade" : "A" }, { "age" : 32, "grade" : "B" }, { "age" : 14, "grade" : "C" }, { "age" : 6, "grade" : "A" } ] 위와 같은 형식의 배열이라고 해보자, grade별 value counting하여 원하는 결과는 다.. 2022. 11. 4.
DateFormatter 한국에 맞게 원하는 format으로 날짜 만들기 NSString * StringDate = @"2022-11-05"; NSDateFormatter * dateFormatter = [NSDateFormatter new]; [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"ko_KR"]]; string으로 되어 있는 날짜 형식에 맞게 format을 맞춘다 [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate * date = [dateFormatter dateFromString: stringDate]; // 2022-11-05 00:00 이 'date'를 원하는 형식의 format으로 만들어 준다.. 2022. 11. 3.
NSArray double 타입의 배열 만들기 NSMutableArray *doubleArr = [[NSMutableArray alloc] initWithCapacity:0]; [doubleArr addObject:[NSNumber numberWithDouble:23.1234]]; 포함 값 찾기 // 방법1 if (배열 containsObject:찾으려는값) { // code } // 방법2 // 이 방법은 json데이터의 배열안에있는 객체에서 값을 찾을 때 사용 // predicateWithFormat: 어떤 값을 찾을지에 따라 달라진다. NSPredicate * predicate = [NSPredicate predicateWithFormat:@"키 IN %@", 찾으려는값]; NSArray * resultArray.. 2022. 11. 2.
UIPickerView pickerview 항목 2개 이상 만들기 NSMutableArray * yearArr; NSMutableArray * monthArr; // 열 개수 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 2; } // 열 데이터 갯수 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { if (component == 0) { return [yearArr count]; } else { return [monthArr count]; } } // 행 높이 - (CGFloat)pickerView:(UIP.. 2022. 11. 2.
NSMutableArray 중복 제거 NSMutableArray *_userIds = [NSMutableArray new]; for( NSInteger i = 0; i < 3; i++ ) { [_userIds insertObject:@"aaaaaaaaaa" atIndex:i]; } NSOrderedSet *userSet = [[NSOrderedSet alloc] initWithArray:_userIds]; _userIds = [[NSMutableArray alloc] initWithArray:[userSet array]]; 출처 : https://mrkn.tistory.com/337 2022. 11. 2.
navigation stack에서 특정 VC 삭제 NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers]; for (int i = 0; i < [navigationArray count]; i++) { if ([[navigationArray objectAtIndex:i] isKindOfClass:[지우려는VC class]]) { [navigationArray removeObjectAtIndex: [navigationArray count] - ([navigationArray count] - i)]; } } self.navigationController.viewControllers = navigationArr.. 2022. 11. 2.
UIScrollView 스크롤을 최하단으로 이동 [self.scroll setContentSize:CGSizeMake(self.view.frame.size.width, self.scroll.frame.size.height + keyboardHeight)]; CGPoint bottom = CGPointMake(0, self.scroll.contentSize.height - self.view.bounds.size.height + self.scroll.contentInset.bottom); if (bottom.y > 0) { [self.scroll setContentOffset:bottom animated:YES]; } 2022. 11. 1.
NSString 문자열 생성 NSString * str1 = [NSString new]; NSString * str2 = [[NSString alloc] initWithString:@"안녕안녕"]; 문자열 합치기 NSString * str1 = [NSString new]; str1 = @"반가워"; NSString * str2 = [[NSString alloc] initWithString:@"안녕안녕"]; NSString * str3 = [str1 stringByAppendingString:str2]; // str3 = 반가워안녕안녕 NSString * str1 = @"안녕"; NSString * str2 = [str1 stringByAppendingString:@" 반가워"]; // 안녕 반가워 문자열 비교 NSStr.. 2022. 10. 27.
UISegmentedControl 선택 상태에 따라 세그타이틀 컬러 변경 - (IBAction)segmentedControlTap:(UISegmentedControl *)sender { NSDictionary *select = @{NSForegroundColorAttributeName: UIColor.redColor}; NSDictionary *normal = @{NSForegroundColorAttributeName: UIcolor.blackColor}; [sender setTitleTextAttributes:normal forState:UIControlStateNormal]; [sender setTitleTextAttributes:select forState:UIControlStateSelected]; } 2022. 10. 19.
300x250