Skip to content

Instantly share code, notes, and snippets.

@setoh2000
setoh2000 / gist:2354043
Created April 10, 2012 19:57
NSMutableOrderedSetを使って2つの配列(array1, array2)を重複なしに合体させてソートされた配列(array3)を得る方法
NSMutableOrderedSet *set = [NSMutableOrderedSet orderedSetWithArray:array1];
[set addObjectsFromArray:array2];
array3 = [set sortedArrayUsingComparator:^(NSString *obj1, NSString *obj2) {
return [obj1 compare:obj2];
}];
@setoh2000
setoh2000 / gist:2340962
Created April 9, 2012 02:38
UITextFieldのカーソルを先頭に移動する方法 (Moving the cursor to the beginning of UITextField)
UITextPosition *newPos = [textField positionFromPosition:textField.beginningOfDocument offset:0];
textField.selectedTextRange = [textField textRangeFromPosition:newPos toPosition:newPos];
[textField setNeedsLayout];
@setoh2000
setoh2000 / gist:2286004
Created April 2, 2012 18:18
自分がModalViewControllerとして表示されたかどうかを調べる
- (BOOL)isModal
{
return (self == [self.navigationController.viewControllers objectAtIndex:0]);
}
@setoh2000
setoh2000 / gist:1953420
Created March 1, 2012 21:39
UITableViewでスクロール停止時に表示されるセルを予想する iOS5以降
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
UITableView *tableView = (UITableView *)scrollView;
int n = tableView.frame.size.height / _cellHeight;
if ((int)tableView.frame.size.height % (int)_cellHeight) n++;
for (int i = 0; i <= n; i++) {
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:CGPointMake(0, targetContentOffset->y + i * _cellHeight)];