Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted by Dmitriy ( 13 years ago )
- (NSArray*)playerGroups {
return [self.playerValues objectForKey:@"groups"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.playerGroups.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSDictionary *currentGroup = [self.playerGroups objectAtIndex:section];
return [currentGroup objectForKey:@"title"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSDictionary *currentGroup = [self.playerGroups objectAtIndex:section];
return [[currentGroup objectForKey:@"notes"] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *currentGroup = [self.playerGroups objectAtIndex:indexPath.section];
NSArray *notesInSection = [currentGroup objectForKey:@"notes"];
NSDictionary *currentNote = [notesInSection objectAtIndex:indexPath.row];
NSString *text = [currentNote objectForKey:@"text"];
CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(tableView.frame.size.width - PADDING * 3, 1000.0f)];
return textSize.height*1.1 + PADDING * 3+10;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableDictionary *fromGroup = [self.playerGroups objectAtIndex:indexPath.section];
NSMutableArray *fromNotesInSection = [fromGroup objectForKey:@"notes"];
[fromNotesInSection removeObjectAtIndex:indexPath.row];
//Writing to the file
NSString *filePath = [DOCUMENTS stringByAppendingPathComponent:@"Players.plist"];
NSMutableDictionary *players = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
NSMutableArray *groupsForSave = self.playerGroups.mutableCopy;
NSMutableDictionary *selectedGroup = [[groupsForSave objectAtIndex:indexPath.section] mutableCopy];
NSMutableArray *groupNotes = [[selectedGroup objectForKey:@"notes"] mutableCopy];
if (groupNotes!=nil) {
[selectedGroup setObject:fromNotesInSection forKey:@"notes"];
[groupsForSave replaceObjectAtIndex:indexPath.section withObject:selectedGroup];
}
[self.playerValues setValue:groupsForSave forKey:@"groups"];
[players setObject:self.playerValues forKey:self.playerName];
[players writeToFile:filePath atomically:YES];
[tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *currentGroup = [self.playerGroups objectAtIndex:indexPath.section];
NSArray *notesInSection = [currentGroup objectForKey:@"notes"];
NSDictionary *currentNote = [notesInSection objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
if (!iPad) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell_iPhone"owner:self options:nil];
cell = [nib objectAtIndex:0];
DYRateView *reter = [[DYRateView alloc] initWithFrame:CGRectMake(tableView.frame.size.width, tableView.rowHeight, 110.0f, 20.0f)
fullStar:[UIImage imageNamed:@"StarFull.png"]
emptyStar:[UIImage imageNamed:@"StarEmpty.png"]];
reter.rate = [[currentNote objectForKey:@"rate"] floatValue];
reter.padding = 5;
reter.alignment = RateViewAlignmentCenter;
reter.editable = YES;
reter.delegate = self;
reter.indexPath = indexPath;
cell.accessoryView = reter;}
else {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell_iPad"owner:self options:nil];
cell = [nib objectAtIndex:0];
DYRateView *reter = [[DYRateView alloc] initWithFrame:CGRectMake(tableView.frame.size.width, tableView.rowHeight, 140.0f, 20.0f)
fullStar:[UIImage imageNamed:@"StarFullLarge.png"]
emptyStar:[UIImage imageNamed:@"StarEmptyLarge.png"]];
reter.rate = [[currentNote objectForKey:@"rate"] floatValue];
reter.padding = 5;
reter.alignment = RateViewAlignmentCenter;
reter.editable = YES;
reter.delegate = self;
reter.indexPath = indexPath;
cell.accessoryView = reter;}
}
NSString *fifi = [NSString stringWithFormat:@"%i. ",indexPath.row+1];
cell.textView.indexPath = indexPath;
cell.textView.editable = NO;
cell.textView.delegate = self;
cell.number.text =fifi;
cell.textView.text = [currentNote objectForKey:@"text"];
return cell;
}
Revise this Paste