簡體   English   中英

在iPhone 5上測試時加載圖像時出錯

[英]Error on loading image when testing on iPhone 5

我正在嘗試在TableCell上設置圖像。

這是我的代碼:

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
    UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
    Parking parking = (tableItems.ToArray () [indexPath.Row] as Parking);

    if (cell == null) {
        cell = new UITableViewCell(UITableViewCellStyle.Subtitle, cellIdentifier);
    }

    cell.TextLabel.Text = parking.Name;

    UIImage img = UIImage.FromBundle ("occupied");
    cell.ImageView.Image = img;

    cell.DetailTextLabel.Text = parking.GenerateSubtitle ();
    cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

    return cell;
}

這在模擬器上測試時工作得很好,但是當我嘗試在iPhone 5上調試它時,我收到此錯誤:

System.InvalidCastException: Cannot cast from source type to destination type.
  at MonoTouch.UIKit.UIImage.FromBundle (System.String name) [0x0001e] in         /Developer/MonoTouch/Source/monotouch/src/UIKit/UIImage.g.cs:198
  at parko_iphone.MainTableSource.GetCell (MonoTouch.UIKit.UITableView tableView,     MonoTouch.Foundation.NSIndexPath indexPath) [0x0004c] in /Users/gertpoppe/projects/parko_iphone/parko_iphone/CustomComponents/MainTableSource.cs:34
  at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
  at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:129
  at parko_iphone.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0002e] in /Users/gertpoppe/projects/parko_iphone/parko_iphone/AppDelegate.cs:35
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at parko_iphone.Application.Main (System.String[] args) [0x00008] in /Users/gertpoppe/projects/parko_iphone/parko_iphone/Main.cs:16

錯誤發生在我加載圖像的行上:

UIImage img = UIImage.FromBundle ("occupied");

嘗試更換:

UIImage img = UIImage.FromBundle ("occupied");

附:

UIImage *img = UIImage.FromBundle ("occupied");

要么

嘗試更換:

UIImage img = UIImage.FromBundle ("occupied");
cell.ImageView.Image = img;

附:

cell.ImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"occupied"]];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM