月別アーカイブ: 2014年9月

COREDATA

平成26年9月6日

マイグレーション調査

//
[newManagedObject setValue:[NSNumber numberWithBool:NO] forKey:@"on_off"];
//

平成26年9月5日

model変更(on_off追加)

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    //modelを変更した場合の対処 その①
    /*
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"WeatherForcaster01.sqlite"];
    [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];

    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }
     */

    //model変更無し

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"WeatherForcaster01.sqlite"];

    if (_persistentStoreCoordinator != nil) {
    return _persistentStoreCoordinator;
    }

    NSError *error = nil;
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

    //modelを変更した場合の対処 その② 実使用無し
    //----------------------------
    // Check if we already have a persistent store
    if ( [[NSFileManager defaultManager] fileExistsAtPath: [storeURL path]] ) {
        NSDictionary *existingPersistentStoreMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType: NSSQLiteStoreType URL: storeURL error: &error];
        if ( !existingPersistentStoreMetadata ) {
            // Something *really* bad has happened to the persistent store
            [NSException raise: NSInternalInconsistencyException format: @"Failed to read metadata for persistent store %@: %@", storeURL, error];
        }

        if ( ![self.managedObjectModel isConfiguration: nil compatibleWithStoreMetadata: existingPersistentStoreMetadata] ) {
            if ( ![[NSFileManager defaultManager] removeItemAtURL: storeURL error: &error] )
                NSLog(@"*** Could not delete persistent store, %@", error);
        } // else the existing persistent store is compatible with the current model - nice!
    } // else no database file yet
    //----------------------------

    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

         Typical reasons for an error here include:
         * The persistent store is not accessible;
         * The schema for the persistent store is incompatible with current managed object model.
         Check the error message to determine what the actual problem was.

         If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.

         If you encounter schema incompatibility errors during development, you can reduce their frequency by:
         * Simply deleting the existing store:
         [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

         * Performing automatic lightweight migration by passing the following dictionary as the options parameter:
         @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}

         Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return _persistentStoreCoordinator;
}

UIBUTTON

平成26年9月5日

- (void)awakeFromNib
{
    // Initialization code
    [self.switch_button setImage:[UIImage imageNamed:@"on.png"] forState:UIControlStateSelected];
    [self.switch_button setImage:[UIImage imageNamed:@"off.png"] forState:UIControlStateNormal];
    switch_button.selected = YES;
    //switch_button.selected = NO;
}

searchbar

平成26年9月4日
階層
スクリーンショット 2014-09-04 1.17.31 PM

search Barを使用する場合の措置について

- (TableViewCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    // 重要 Search Barを使用する場合は、self.をtableViewの頭にいれる。
    //TableViewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
    TableViewCustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
    //
    //
}

UICOLOR

平成26年9月3日(水曜日)

//
_view2.backgroundColor=[UIColor colorWithRed:0.96 green:0.96 blue:0.86 alpha:0.3];
//
//
cell.detailTextLabel.textColor = [UIColor greenColor];
//

UIScroll View

平成26年9月2日(火曜日)

  • Scroll View追加
  • その下位にView追加
  • Scroll View→add New constrain (上下左右 0 0 0 0)
  • View→ add New constrain (上下左右 0 0 0 0)
  • View→ width,height設定
  • View→Center X Alignment設定

テーブルビューでカスタムセルを使う。

平成26年9月1日(月曜日)〜

XIBファイル作成
file → new → user interface → empty
uitablebiewcellドラッグ
label ドラッグ
button ドラッグ
設定 custom
設定 identifier Cell

CLASSファイル作成
TableViewCustomCell

両者のリンク
@property (weak, nonatomic) IBOutlet UILabel *str1;
@synthesize str1;

segue設定(showDetail)

UIViewController

@property (strong, nonatomic) IBOutlet UITableView *tableView;

TableViewContoroller.m

#import TableViewCustomCell.h;

nibにて使用

static NSString * const TableViewCustomCellIdentifier = TableViewCustomCell;

viewdidload

- (void)viewDidLoad
{
[super viewDidLoad];
// カスタマイズしたセルをテーブルビューにセット
UINib *nib = [UINib nibWithNibName:TableViewCustomCellIdentifier bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"Cell];
//[self.searchDisplayController.searchResultsTableView registerNib:nib forCellReuseIdentifier:@"Cell];
}

cellForRowAtIndexPath

// テーブルセル表示① cellForRowAtIndexPath
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (TableViewCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    // 重要 カスタムセル
    //TableViewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
    TableViewCustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier ];

    /*
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    */

    if (cell == nil) {
        cell = [[TableViewCustomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}

heightForRowAtIndexPath

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [TableViewCustomCell rowHeight];
}

didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// The table view should not be re-orderable.
//NSLog(@"push");

// セグエで画面遷移させる → prepareForSegueが発生
//prepareForSegueが発生
[self performSegueWithIdentifier:@"showDetail" sender:self.tableView];
}

configureCell

- (void)configureCell:(TableViewCustomCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
//cell.textLabel.text = [[object valueForKey:@"timeStamp"] description];
cell.name.text = [[object valueForKey:@"timeStamp"] description];

}

UIBUTTON

平成26年9月1日(月曜日)

XIB設定(button設定)
TYPE →CUSTOM
STATECONFIG→ SELECTED

TableViewCustomCell.h

@property (weak, nonatomic) IBOutlet UIButton *button; @end

 

TableViewCustomCell.m

ボタン押下

<pre>- (IBAction)press_button:(UIButton *)sender {

// _button.selected = true;
NSLog(@"press!!");
if (_button.selected == true) {
_button.selected = false;
} else if(_button.selected == false) {
_button.selected = true;
}
}

ON OFF 背景画像切り替え

- (void)awakeFromNib
{
// Initialization code
NSLog(@"press!!");
[self.button setImage:[UIImage imageNamed:@"5.png"] forState:UIControlStateNormal];
[self.button setImage:[UIImage imageNamed:@"3.png"] forState:UIControlStateSelected];
}