سؤال

في طلبي، أنا أحمل الصور على خلايا جدول. ولكن، عندما قمت بتمرير الجدول، تنطلق الصورة من مشهد الطاولة (ترتفع)، ولن تكون هناك حتى لو قمت بالتمرير مرة أخرى.

customcell.h.

#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell<UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
UIViewController *viewController;
UIImageView *imageView;
UIButton *button;
@property (nonatomic, retain) IBOutlet UIImageView *imageView; 
@property (nonatomic, assign)UIViewController *viewController;
@property (nonatomic, retain) IBOutlet UIButton *button;
-(IBAction)selectExistingPicture1;

@end
}

customcell.m.

    #import "CustomCell.h"
    @implementation CustomCell
@synthesize imageView;
@synthesize viewController;
@synthesize button;
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 
    [picker dismissModalViewControllerAnimated:YES]; 
} 

- (IBAction)selectExistingPicture1 { 
        if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self; 
        picker.allowsImageEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self.viewController presentModalViewController:picker animated:YES];
        [picker release];
    } 
    else { 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil]; 
        [alert show]; 
        [alert release]; 
    } 
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {


    UIImage *thumbnail = [image _imageScaledToSize:CGSizeMake(80, 80) interpolationQuality:1];
    /*CGSize newSize = CGSizeMake(80, 80);
    UIGraphicsBeginImageContext( newSize );
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();*/
    imageView.image = thumbnail;

    [picker dismissModalViewControllerAnimated:YES]; 


}  

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // Initialization code
    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc {
    [imageView release];
    [viewController release];
    [button release];

    [super dealloc];
}


@end

cameraviewcontroller.h.

#import <UIKit/UIKit.h>

@interface Camera1ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> {      

}

@end

cameraviewcontroller.m.

#import "Camera1ViewController.h"
#import "CustomCell.h"

@implementation Camera1ViewController

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {

    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [i
    [super dealloc];
}


 #pragma mark Table Data Source Methods 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 25; 
} 

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *CustomCellIdentifier = @"CustomCellIdentifier";

          CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
     if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CustomCellIdentifier] autorelease];
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self
                                                    options:nil];
         for (id currentObject in nib){
             if ([currentObject isKindOfClass:[CustomCell class]]){
                 cell = (CustomCell *)currentObject;
                 cell.viewController = self;
                 break;
             }
         }

     }
     //dont know what to do here. 
     return cell;

} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 100; 
} 


- (NSString *)tableView:(UITableView *)tableView 
titleForHeaderInSection:(NSInteger)section { 
    NSString *key = @"Album"; 
    return key; 
} 
@end
هل كانت مفيدة؟

المحلول

يمضغ مشكلتك بشكل مستقل إليك في إعادة استخدام الخلايا وعدم إعادة التأقلم بشكل صحيح عندما يعودون إلى الشاشة. انقر فوق موافق، لذلك عند الخروج من الرأي في عرض جدول، فهي غير تفريغ لحفظ الذاكرة، عند اختيار إعادة استخدام خلية مع معرف واحد فقط، يعني أنه في كل مرة خلية تستخدم هذا المعرف يأتي على الشاشة التي سيعيدها الجدول خلية من هذا النوع (ولكن ليست الخلية الأصلية التي قمت بتكوينها في المرة الأولى حولها) عندما تعود جولة يجب أن تفترض أنها "قذرة" ويجب عليك إعادة تهيئة الصورة ومحتواه، إذا كنت لا تحصل عليه النتائج غير المرغوبة كما ترى.

بديل آخر (على الرغم من أنه ليس جيدا للمحاولات مع الكثير من الخلايا) هو إعطاء خلايا ACH ه المعرف الفريد، والآن أنت مضمون خلاياك لن تكون "قذرة" لأن هناك شخص واحد إلى تعيين واحد بين المعرف والخلايا، أسفل جانب من ذلك هو أنك ستستخدم الكثير من الذاكرة، والذي يهزم الغرض من إعادة استخدام الخلايا (كما لو كانت خلايا إعادة استخدام Y Ou Werent على الإطلاق) ... آمل أن يكون هذا يساعد

نصائح أخرى

من النظر إلى التعليمات البرمجية الخاصة بك في المنشور السابق:

NSUInteger s= indexPath.section;
 //[cell setText:[NSString stringWithFormat:@"I am cell %d", indexPath.row]];

 NSUInteger r = indexPath.row;
  cell.imageView.image = nil;
 for (s;s==0;s++)
 for(r;r==0;r++)
 {           
      UIImage *img=imageView.image;
     cell.imageView.image = img;
     }
 return cell;

}

لست متأكدا من أن الحلقات مخصصة، ولكن في أي وقت تحتاج خلية إلى إعادة رسمها، فأنت تحدد UiimageView في الخلية إلى imageView.image (أفترض أن ImageView هو خاصية UiviewController الخاصة بك) لذلك في جوهرك تقوم بالكتابة فوق ما هو موجود بالفعل بهذا

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top