【Loading nib file】Loading a nib file

本文介绍了在iOS应用中使用不同方法加载Nib文件的过程。包括从当前包加载、使用NSNib类实例化以及替换Nib文件中的占位符对象等实用技巧。

Loading a nib file from the current bundle 

- (BOOL)loadMyNibFile
{
    // The myNib file must be in the bundle that defines self's class.
    if (![NSBundle loadNibNamed:@"myNib" owner:self])
    {
        NSLog(@"Warning! Could not load myNib file.\n");
return NO; }
return YES; }



Loading a nib in an iPhone application 

<span style="font-size:18px;">- (BOOL)loadMyNibFile
{
    NSArray*    topLevelObjs = nil;
    topLevelObjs = [[NSBundle mainBundle] loadNibNamed:@"myNib" owner:self
options:nil];
    if (topLevelObjs == nil)
    {
        NSLog(@"Error! Could not load myNib file.\n");
return NO; }
return YES; }</span>



Loading a nib file using NSNib 

- (NSArray*)loadMyNibFile
{
    NSNib*      aNib = [[NSNib alloc] initWithNibNamed:@"MyPanel" bundle:nil];
    NSArray*    topLevelObjs = nil;
    if (![aNib instantiateNibWithOwner:self topLevelObjects:&topLevelObjs])
    {
        NSLog(@"Warning! Could not load nib file.\n");
return nil; }
    // Release the raw nib data.
    [aNib release];
    // Release the top-level objects so that they are just owned by the array.
    [topLevelObjs makeObjectsPerformSelector:@selector(release)];
    // Do not autorelease topLevelObjs.
    return topLevelObjs;
}

Replacing placeholder objects in a nib file 

- (void)applicationDidFinishLaunching:(UIApplication *)application
  {
      NSArray*    topLevelObjs = nil;
      NSDictionary*    proxies = [NSDictionary dictionaryWithObject:self
  forKey:@"AppDelegate"];
      NSDictionary*    options = [NSDictionary dictionaryWithObject:proxies
  forKey:UINibExternalObjects];
      topLevelObjs = [[NSBundle mainBundle] loadNibNamed:@"Main" owner:self
  options:options];
      if ([topLevelObjs count] == 0)
      {
          NSLog(@"Warning! Could not load myNib file.\n");
          return;
}
      // Show window
      [window makeKeyAndVisible];
  }



Traceback (most recent call last): File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\transforms\transform.py”, line 141, in apply_transform return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\transforms\transform.py”, line 98, in _apply_transform return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\transforms\io\array.py”, line 291, in call img_array, meta_data = reader.get_data(img) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\data\image_reader.py”, line 952, in get_data data = self._get_array_data(i) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\data\image_reader.py”, line 1026, in _get_array_data return np.asanyarray(img.dataobj, order=“C”) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\nibabel\arrayproxy.py”, line 454, in array arr = self._get_scaled(dtype=dtype, slicer=()) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\nibabel\arrayproxy.py”, line 421, in _get_scaled scaled = apply_read_scaling(self._get_unscaled(slicer=slicer), scl_slope, scl_inter) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\nibabel\arrayproxy.py”, line 391, in _get_unscaled return array_from_file( File “D:\Anaconda\envs\cpupytorch\lib\site-packages\nibabel\volumeutils.py”, line 467, in array_from_file n_read = infile.readinto(data_bytes) File “D:\Anaconda\envs\cpupytorch\lib\gzip.py”, line 300, in read return self._buffer.read(size) File “D:\Anaconda\envs\cpupytorch\lib_compression.py”, line 68, in readinto data = self.read(len(byte_view)) File “D:\Anaconda\envs\cpupytorch\lib\gzip.py”, line 506, in read raise EOFError("Compressed file ended before the " EOFError: Compressed file ended before the end-of-stream marker was reached The above exception was the direct cause of the following exception: Traceback (most recent call last): File “D:\PythonProject\train_3d_cnn.py”, line 61, in <module> for images, labels in train_loader: File “D:\Anaconda\envs\cpupytorch\lib\site-packages\torch\utils\data\dataloader.py”, line 708, in next data = self._next_data() File “D:\Anaconda\envs\cpupytorch\lib\site-packages\torch\utils\data\dataloader.py”, line 764, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File “D:\Anaconda\envs\cpupytorch\lib\site-packages\torch\utils\data_utils\fetch.py”, line 52, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File “D:\Anaconda\envs\cpupytorch\lib\site-packages\torch\utils\data_utils\fetch.py”, line 52, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File “D:\PythonProject\train_3d_cnn.py”, line 38, in getitem img = self.transform(self.data_files[idx]) File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\transforms\compose.py”, line 335, in call result = execute_compose( File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\transforms\compose.py”, line 111, in execute_compose data = apply_transform( File “D:\Anaconda\envs\cpupytorch\lib\site-packages\monai\transforms\transform.py”, line 171, in apply_transform raise RuntimeError(f"applying transform {transform}") from e RuntimeError: applying transform <monai.transforms.io.array.LoadImage object at 0x00000204AE39BDC0>
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值