hi expert, i did an application which has imageview to capture image from camera and a button where button is clicked pickerView will appear by actionsheet and will choose type of image(jpg, png, bmp..), once select from picker, button title will change according to the pickerView result,
then i try to convert this to UITableView, which has 2 section ( 1 for image and 1 for select the type of the image,
now i'm having problem where i try to imageView into the cell but image was overlapping other cell, and once image capture from camera that imageView not updated but once scroll the table than only updated,
another problem is, once select 2nd section i able to call the pickerView to choose the image type as previously, but once select from pickerView i don't how to updated the cell.text
below is my code, can anyone help here or improve it,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return NSLocalizedString(@"Image", @"");
break;
case 1:
return NSLocalizedString(@"Image type", @"");
break;
default:
break;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];
}
switch (indexPath.section) {
case 0:
{
UIImageView *abc = [[UIImageView alloc] initWithFrame:CGRectMake(5,5,100,100)];
abc.image = imageView.image;
[cell addSubview:abc];
}
break;
case 1:
cell.textLabel.text = @"- Click here -";
break;
default:
break;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell"] autorelease];
}
if(indexPath.section == 0) {
NSLog(@"selected %d",indexPath.section);
}
if(indexPath.section == 1) {
NSLog(@"selected %d",indexPath.section);
[self chooseType];
}
}
- (void)chooseType{
actionSheet = [[UIActionSheet alloc] initWithTitle:@""
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
NSArray *typeObject = [NSArray arrayWithObjects:@".jpg",@".png",@".bmp",nil];
self.pickerData = typeObject;
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;
pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(TypeDonePick)];
[barItems addObject:doneBtn];
[pickerDateToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerDateToolbar];
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
[pickerView release];
[actionSheet release];
}
- (void)TypeDonePick
{
NSInteger row = [pickerView selectedRowInComponent:0];
titleCause.textColor = [UIColor blackColor];
titleCause.text = [pickerData objectAtIndex:row];
NSLog(@" %@ ",titleCause.text);
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
is it possible to change cell test from outside range UITable function
thanks