Menu

Tie a TDPF Switch to a TDPFUITableView

Bryan
2014-02-03
2014-02-10
  • Bryan

    Bryan - 2014-02-03

    Hello,
    I would like to put a TDPFSwitch into a TDPFUITableView Cell.
    Is this possible.
    I am able to place on on the table view, but it does not seem to be tied to a cell.
    Maybe I should use some other control?

    Thanks for any advice.
    Regards,
    Bryan

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-02-03

    Hi Bryan

    You can add, create your TDPFSwitch in DrawCell event

    Regards

     
  • Bryan

    Bryan - 2014-02-03

    Hello Babak,
    Thank you for your reply, but when I implement OnDrawCell, It will not compile because the compiler does not recognize "TTableItem". It shows undeclared identifier.

    procedure TfrmMain.tvSevereWeatherDrawCell(Sender: TObject; Section,
    RowNo: Integer; TableItem: TTableItem;
    var Objects: TArray<DPF.iOS.BaseControl.TDPFiOSBaseControl>);

    Regards,
    Bryan

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-02-03

    Hi Bryan

    Add DPF.iOS.UITableViewItems into your uses list.

    regards

     
  • Bryan

    Bryan - 2014-02-03

    Thank you.

     
  • Bryan

    Bryan - 2014-02-04

    Hello Babak,
    I've tried to do this, but I just don't know how...
    Can you give me a little help :-)

    procedure TfrmMain.tvStartPageTableViewDrawCell(Sender: TObject; Section,
      RowNo: Integer; TableItem: TTableItem;
      var Objects: TArray<DPF.iOS.BaseControl.TDPFiOSBaseControl>);
    var
      aSwitch : TDPFSwitch;
    begin
      if RowNo = 3 then
      begin
        aSwitch := TDPFSwitch.Create(frmMain);
        aSwitch.ISON := True;
        Objects[0].AddObject(aSwitch);
        //Objects[0].Align := alRight;
      end;
    end;
    
     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-02-04

    Hi Bryan

    Download last source [code] and see [TableViewCustomView] Demo.

    Regards

     

    Related

    Code: code

  • Bryan

    Bryan - 2014-02-05

    Hi Babak,
    I was able to see the demo and modify it to add a switch. Thanks for the example.
    But when I try to set the switch alignment, it will not accept alRight. Compiler says undeclared identifier 'alRight'

      if MustBeCreate then
      begin
        TDPFSwitch( Objects[4] )               := TDPFSwitch.Create( nil );
        TDPFSwitch( Objects[4] ).Width         := 77;
        TDPFSwitch( Objects[4] ).Height        := 27;
        TDPFSwitch( Objects[4] ).Position.x    := DPFUITableView1.Width - 80;
        TDPFSwitch( Objects[4] ).Align         := alRight;
        TDPFSwitch( Objects[4] ).Margins.Right := 5;
        TDPFSwitch( Objects[4] ).Position.Y    := 40;
      end;
      TDPFSwitch( Objects[4] ).ISON          := True;
    end;
    

    Cheers,
    Bryan

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-02-05

    Hi Bryan

    don't use alignment for cell components, it's better set position manually,
    for alRight:

    TDPFSwitch( Objects[4] ).Position.y    := 0; 
    TDPFSwitch( Objects[4] ).Position.x    := DPFUITableView1.Width - 80;
    

    regards

     
  • Bryan

    Bryan - 2014-02-09

    Hi Babak,
    Thank you for the advice.

    I am still having trouble with adding a switch. I am able to do it with your demo app, but in my app it will not work.

    1. I have a TableView with 3 different sections. I only want to add the TDPFSwitch to the table items in section 1.

    2. The TableItems in section 1 already have a an item description and item text set to what I want in design time (2 Objects).

    3. I've added the code below to only add the TDPFSwitch to the Table Items in section 1, but when I run the app, it removes text from table items in section 0,1,2. and it still does not add the Switch.

    4. Since there are only 2 objects in the TableItem in section 1 (ItemText and ItemDescription), I set the object length to 3 to add space for the switch.

    This is the code i'm using:

    procedure TframeSevere.tvSevereWeatherDrawCell(Sender: TObject; Section,
      RowNo: Integer; TableItem: TTableItem;
      var Objects: TArray<DPF.iOS.BaseControl.TDPFiOSBaseControl>);
    begin
      if Section = 1 then
      begin
        SetLength( Objects, 3);
        TDPFSwitch( Objects[2] )  := TDPFSwitch.Create( nil );
        TDPFSwitch( Objects[2] ).ISON := True;
        TDPFSwitch( Objects[2] ).Position.X := 200;
        TDPFSwitch( Objects[2] ).Position.Y := 10;
        TDPFSwitch( Objects[2] ).Tag := RowNo;
      end;
    end;
    

    Just in case it is hard to understand what I am talking about I've added my sample shell of an app to this post.

    On another note, it appears the TDPFMapView is overlapping the toolbar at the top and there is a space at the bottom of the app.

    Any suggestions?

    Many thanks for your hard work on this component set. It is truly amazing.
    Sorry for all the questions, I am new to iOS programming.

    Kind Regards,
    Bryan

     

    Last edit: Bryan 2014-02-09
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-02-09

    Hi Bryan

    Download last source [code] from SVN and see TableViewCustomViewSection Demo,

    • Added TDPFUITableView Handled parameter in OnDrawCell event
    • Added TDPFUITableView Handled parameter in OnApplyFrameData event

    Regards

     

    Related

    Code: code

  • Bryan

    Bryan - 2014-02-09

    Hi Babak,
    I am able to put the switch in the TableView in the correct row, but there still seems to be a problem.
    When I create the section in design view and make it Style tvscSubtitle, I get the main title and the subtitle, but when I run the app, the TableItem.ItemText.Text is wiped out, but the item description is still there.

    To make a simple test of this, create a TableView in design time, with a table item style tvcsSubtitle, and set the ItemText and ItemDescription.
    Next, add the method OnDrawCell, but just comment out the method code area.

    procedure TForm1.DPFUITableView1DrawCell(Sender: TObject; Section,
      RowNo: Integer; TableItem: TTableItem;
      var Objects: TArray<DPF.iOS.BaseControl.TDPFiOSBaseControl>;
      var Handled: Boolean);
    begin
    // nothing here
    end;
    
     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-02-09

    Hi Bryan

    I added Handled parameterfor this purpose,
    Set Handled := false; when you want default draw (text, description) or
    Set Handled := true; your own custom draw;

    Regards

     

    Last edit: Babak Yaghoobi 2014-02-09
  • Bryan

    Bryan - 2014-02-09

    Hi Babak,
    So if I understand you correctly, I have to draw everything within a row if I add anything custom?

    So if I want to add a switch, I have to manually (in code) make the ItemText and ItemDescription in code also?

    Bryan

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-02-10

    Hi Bryan

    If you want to UITable draw default setting set Handled := false if you want to do not draw default setting Handled := true;

    Now, if you want add a switch, and you have to manually make the itemText and iTemDescription set Handled := false;

    Regards

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.