按钮和文本框不显示文本

时间:2015-05-13 01:00:42

标签: microsoft-band

我正在尝试创建一个包含3个页面的图块,每个页面都包含一个文本框和一个按钮。这是我的代码

[self.client.personalizationManager
     themeWithCompletionHandler:^(MSBTheme *theme, NSError *error){
         if (error){
             // handle error
             NSLog(@"Error: %@", error);
         }
         NSLog(@"Creating tile...");
         NSString *tileName = @"SnapBand";

         // Create Tile Icon
         MSBIcon *tileIcon = [MSBIcon iconWithUIImage:[UIImage imageNamed:@"Band46x46.png"] error:nil];

         // Create small Icon
         MSBIcon *smallIcon = [MSBIcon iconWithUIImage:[UIImage imageNamed:@"Band24x24.png"] error:nil];

         // Create a Tile
         NSUUID *tileID = [[NSUUID alloc] initWithUUIDString:@"6120f0c7-fec4-44b0-99fa-04c7ca6cf869"];
         MSBTile *tile = [MSBTile tileWithId:tileID name:tileName tileIcon:tileIcon smallIcon:smallIcon error:nil];

         // Create a Picture Text Block
         MSBPageTextBlock *pictureTextBlock = [self createMSBandTextBlockWithParameters:10 WithTheme:theme];

         // Create a Picture Snap Button
         MSBPageTextButton *pictureButton = [self createMSBandActioButtonWithParameters:11 WithTheme:theme];

         // Create a Movie Text Block
         MSBPageTextBlock *movieTextBlock = [self createMSBandTextBlockWithParameters:20 WithTheme:theme];

         // Create a Movie Snap Button
         MSBPageTextButton *movieButton = [self createMSBandActioButtonWithParameters:21 WithTheme:theme];

         // Create a Brust Text Block
         MSBPageTextBlock *brustTextBlock = [self createMSBandTextBlockWithParameters:30 WithTheme:theme];

         // Create a Brust Snap Button
         MSBPageTextButton *brustButton = [self createMSBandActioButtonWithParameters:31 WithTheme:theme];

         MSBPageFlowPanel *pictureFlowPanel = [[MSBPageFlowPanel alloc] initWithRect:[MSBPageRect rectWithX:0 y:0 width:245 height:105]];
         MSBPageFlowPanel *movieFlowPanel = [[MSBPageFlowPanel alloc] initWithRect:[MSBPageRect rectWithX:245 y:0 width:245 height:105]];
         MSBPageFlowPanel *brustFlowPanel = [[MSBPageFlowPanel alloc] initWithRect:[MSBPageRect rectWithX:490 y:0 width:245 height:105]];

         [pictureFlowPanel addElements:@[pictureTextBlock, pictureButton]];
         [movieFlowPanel addElements:@[movieTextBlock, movieButton]];
         [brustFlowPanel addElements:@[brustTextBlock, brustButton]];

         MSBPageScrollFlowPanel *panel = [[MSBPageScrollFlowPanel alloc] initWithRect:[MSBPageRect rectWithX:0 y:0 width:245 height:105]];
         panel.horizontalAlignment = MSBPageHorizontalAlignmentLeft;
         panel.verticalAlignment = MSBPageVerticalAlignmentTop;
         panel.orientation = MSBPageFlowPanelOrientationHorizontal;

         [panel addElements:@[pictureFlowPanel, movieFlowPanel, brustButton]];
         MSBPageLayout *layout = [[MSBPageLayout alloc] init];
         layout.root = panel;

         [tile.pageLayouts addObject:layout];

         [self.client.tileManager addTile:tile completionHandler:^(NSError *error) {
             if (!error || error.code == MSBErrorTypeTileAlreadyExist)
             {
                 NSLog(@"Creating page...");
                 NSUUID *pageID = [[NSUUID alloc] initWithUUIDString:@"a234e9ba-1c09-46c3-b3b3-12bb1c9cf90f"];
                 NSArray *pageValues = @[[MSBPageTextButtonData pageTextButtonDataWithElementId:11 text:@"Snap!" error:nil],
                                         [MSBPageTextBlockData pageTextBlockDataWithElementId:10 text:@"Picture" error:nil]];
                 MSBPageData *pageDataPicture = [MSBPageData pageDataWithId:pageID layoutIndex:0 value:pageValues];

                 NSUUID *pageIDMovie = [[NSUUID alloc] initWithUUIDString:@"1535d78b-9784-4892-a94c-030df63de453"];
                 NSArray *pageValuesMovie = @[[MSBPageTextButtonData pageTextButtonDataWithElementId:21 text:@"Snap!" error:nil],
                                         [MSBPageTextBlockData pageTextBlockDataWithElementId:20 text:@"Movie" error:nil]];
                 MSBPageData *pageDataMovie = [MSBPageData pageDataWithId:pageIDMovie layoutIndex:1 value:pageValuesMovie];

                 NSUUID *pageIDBrust = [[NSUUID alloc] initWithUUIDString:@"1fd74789-3936-4324-a1fc-3e1d66d6e189"];
                 NSArray *pageValuesBrust = @[[MSBPageTextButtonData pageTextButtonDataWithElementId:31 text:@"Snap!" error:nil],
                                              [MSBPageTextBlockData pageTextBlockDataWithElementId:30 text:@"Brust" error:nil]];
                 MSBPageData *pageDataBrust = [MSBPageData pageDataWithId:pageIDBrust layoutIndex:2 value:pageValuesBrust];


                 [self.client.tileManager setPages:@[pageDataPicture, pageDataMovie, pageDataBrust] tileId:tile.tileId completionHandler:^(NSError *error) {
                     if (!error)
                     {
                         NSLog(@"Completed band tile creation");
                         [self.snapPictureButton setBackgroundImage:[UIImage imageNamed:@"GreenStatus"] forState:UIControlStateNormal];
                         [self sendHapticFeedback];
                     }
                     else
                     {
                         NSLog(@"Error: %@", error.localizedDescription);
                     }
                 }];
             }
             else
             {
                 NSLog(@"Error: %@", error.localizedDescription);
             }
         }];

     }];

我创建了一个构造函数方法来生成文本框和按钮,方法是:

 -(MSBPageTextBlock *) createMSBandTextBlockWithParameters:(int)textBoxID WithTheme:(MSBTheme *) theme{
    MSBPageTextBlock *textBlock = [[MSBPageTextBlock alloc] initWithRect:[MSBPageRect rectWithX:0 y:0 width:200 height:40] font:MSBPageTextBlockFontSmall];
    textBlock.elementId = textBoxID;
    textBlock.baselineAlignment = MSBPageTextBlockBaselineAlignmentRelative;
    textBlock.horizontalAlignment = MSBPageHorizontalAlignmentLeft;
    textBlock.autoWidth = YES;
    textBlock.color = theme.baseColor;
    textBlock.margins = [MSBPageMargins marginsWithLeft:15 top:0 right:0 bottom:0];

    return textBlock;
}

-(MSBPageTextButton *) createMSBandActioButtonWithParameters:(int)textBoxID WithTheme:(MSBTheme *) theme{
    MSBPageTextButton *actionButton = [[MSBPageTextButton alloc] initWithRect:[MSBPageRect rectWithX:0 y:0 width:200 height:40]];
    actionButton.elementId = textBoxID;
    actionButton.horizontalAlignment = MSBPageHorizontalAlignmentCenter;
    actionButton.pressedColor = theme.baseColor;
    actionButton.margins = [MSBPageMargins marginsWithLeft:15 top:0 right:0 bottom:0];

    return actionButton;
}

按钮和文本框没有显示乐队上的任何文字,我可以看到乐队上的按钮,第三个按钮的位置不正确,两个按钮中没有文字。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

看起来您已经使用水平滚动面板创建了一个布局。而那个面板有pictureFlowPanel,movieFlowPanel,brustButton作为其元素。

因此,当您创建页面时,您只需要创建一个具有上述布局的页面。但是,在您的代码中,我看到您正在尝试使用布局索引0,1和2创建三个页面。只有布局0有效且布局1和2不存在。

一种可能的解决方法是将布局分成三个独立的布局:

MSBPageLayout *pictureLayout = [[MSBPageLayout alloc] init];
pictureLayout.root = pictureFlowPanel;
[tile.pageLayouts addObject:pictureLayout]; //Layout 0

MSBPageLayout *movieLayout = [[MSBPageLayout alloc] init];
movieLayout.root = movieFlowPanel;
[tile.pageLayouts addObject:movieLayout]; //Layout 1

MSBPageLayout *burstLayout = [[MSBPageLayout alloc] init];
burstLayout.root = burstFlowPanel;
[tile.pageLayouts addObject:burstLayout]; //Layout 2