UISegmentControl不起作用?

时间:2017-03-15 01:27:19

标签: ios objective-c

我已经在导航栏中连接了一个UISegmentControl。它似乎很好,但是当我点击不同的段时,它不会执行情况1和1。 2 - 它只停留在案例0上(因此,保持记录和#34;请求!")。知道为什么会这样吗?请参阅以下代码:

- (IBAction)segmentControl:(id)sender {

        switch (self.segmentControl.selectedSegmentIndex)
        {


            case 0:

                [self.tableView setHidden:NO];
                [self.neighboursView setHidden:YES];
                  [self.friendsView setHidden:YES];

                NSLog(@"Requests!");

                break;



            case 1: 

                [self.tableView setHidden:YES];
                [self.friendsView setHidden:NO];
                [self.neighboursView setHidden:YES];

                [self acceptedFriends];
                     NSLog(@"Friends!");

                break;



            case 2:

                [self.tableView setHidden:YES];
                [self.neighboursView setHidden:NO];
                [self.friendsView setHidden:YES];

                [self neighbourInfo];
                     NSLog(@"Neighbours!");
                break;


        }


    }

2 个答案:

答案 0 :(得分:0)

试试这个;

    -(IBAction)segmentControl:(id)sender {

      UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
      NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;

      switch (selectedSegment)
            {
             case 0:
            .

            .

            .
            }
     }

答案 1 :(得分:0)

enter image description here

只需在Storyboard导航栏上拖放片段控件即可。

创建价值变更行动

enter image description here

io.write("file name?:")
local file=io.read()
os.execute("clear;clear;clear;clear;clear;")
if os.execute("test -e Desktop/"..file) == true then
    os.execute("rm -f Desktop/"..file)
end
local p = {}
while true do
  io.write("-")
  local u = io.read()
  if u ~= "" then
    table.insert(p,u)
  else
    break
  end
end
print("saveing...")
local ty=io.open("Desktop/"..file,"w+")
for i,ie in ipairs(p) do
  ty:write(ie,"\n")
  os.execute("sleep 0.1")
  ty:flush()
end
print("saved")
ty:close()

enter image description here