لماذا تختفي هذا uiimage من UitableViewCell عند الدوران إلى المناظر الطبيعية؟

StackOverflow https://stackoverflow.com/questions/3047602

سؤال

أحاول إعداد uitableViewCell يمكن أن يكون لها صورة في الزاوية اليمنى العليا.

لقد عملت في وضع Portrait ، لكن عندما أتدوير إلى المناظر الطبيعية ، تختفي الصورة.

هذا هو الرمز:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImage *cornerImage = [UIImage imageNamed:@"star_corner.png"];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(cell.contentView.bounds.size.width - cornerImage.size.width,
                                                                               0,
                                                                               cornerImage.size.width,
                                                                               cornerImage.size.height)];
        imageView.tag = kCornerImageViewTag;
        [cell.contentView addSubview:imageView];
        [imageView release];
    }

    UIImageView *theView = (UIImageView *)[cell.contentView viewWithTag:kCornerImageViewTag];
    [theView setImage: [UIImage imageNamed:@"star_corner.png"]];

    cell.textLabel.text = @"the text label";
    return cell;
}

ومن المثير للاهتمام ، إذا قمت بتعليق "Cell.TextLabel.text =" Line ، فإن الصورة تظهر في المناظر الطبيعية ... على الرغم من أنها لا تتحول إلى أقصى اليمين.

إذا كان هناك أي شيء آخر أفعله خطأ هنا ، فيرجى إخبارنا بذلك.

شكرا مقدما لأي مساعدة.

هل كانت مفيدة؟

المحلول

لقد اكتشفت هذا. كان الحل هو إنشاء اثنين من uiimageview ... واحدة لصورة ركن النجوم ، وواحد لصورة خلفية الخلية.

لقد أضفت Star Corner UiimageView كمظهر فرعي إلى صورة الخلفية UiimageView ، ثم قمت بتعيين ذلك إلى cell.backgroundview.

يضع Star UiimageView نفسه بشكل صحيح عن طريق استخدام:

starImageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

وبما أن الأمر برمته يتم تعيينه إلى cell.backgroundview (بدلاً من cell.contentView) ، فإنه لا يتأثر بزر حذف الخلية أو إعادة ترتيب عناصر التحكم.

نصائح أخرى

يجب أن يستجيب UiviewController الخاص بك إلى deRotateFromInterfaceorientation.

في هذه الطريقة ، يمكنك التكرار من خلال الخلايا ، والحصول على uiimageview مع [cell viewwithtag] وتعديل خاصية الإطار وفقًا لأبعاد الخلية الجديدة (cell.contentview.bounds).

حظا طيبا وفقك الله!

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